{"record":{"id":"f101738e7a2bdacc","repo":"HKUDS/Vibe-Trading","slug":"valuation-on-when-must-be-numeric-got-raw-valu","errorCode":null,"errorMessage":"valuation on {when} must be numeric, got {raw_value!r}","messagePattern":"valuation on (.+?) must be numeric, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/performance.py","lineNumber":332,"sourceCode":"                raise ValueError(\n                    f\"valuations[{index}] must have exactly two elements \"\n                    f\"(date, value), got {len(pair)}\"\n                )\n            raw_items.append((pair[0], pair[1]))\n\n    if len(raw_items) < 2:\n        raise ValueError(\n            \"a return needs an opening and a closing valuation; got \"\n            f\"{len(raw_items)}\"\n        )\n\n    resolved: list[tuple[date, float]] = []\n    for raw_date, raw_value in raw_items:\n        when = normalize_date(raw_date, field_name=\"valuation date\")\n        try:\n            value = float(raw_value)\n        except (TypeError, ValueError) as exc:\n            raise ValueError(\n                f\"valuation on {when} must be numeric, got {raw_value!r}\"\n            ) from exc\n        if not math.isfinite(value):\n            raise ValueError(\n                f\"valuation on {when} must be finite, got {raw_value!r}; a \"\n                \"missing mark must be fixed at the source, not carried as NaN\"\n            )\n        resolved.append((when, value))\n\n    resolved.sort(key=lambda item: item[0])\n    for earlier, later in zip(resolved, resolved[1:], strict=False):\n        if earlier[0] == later[0]:\n            raise ValueError(\n                f\"two valuations share the date {earlier[0]}; a single day can \"\n                \"carry only one mark\"\n            )\n    return tuple(resolved)\n","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/performance.py#L314-L350","documentation":"Each valuation value is coerced with float(); if that raises TypeError/ValueError the item is not numeric and _normalize_valuations reports the date and the offending value. This catches strings like 'N/A', None, Decimal-with-comma formats, or objects without __float__ before they poison the return computation.","triggerScenarios":"Passing [('2024-01-01', 'N/A'), ...], a value of None from a sparse DB column, or a string '1,050.00' with a thousands separator — float() rejects all of these.","commonSituations":"CSV import with empty cells becoming None or ''; locale-formatted numbers; ORM models returning Decimal is fine but custom Money objects without __float__ are not; mixed dtype object columns in pandas.","solutions":["Clean values before calling: coerce with pd.to_numeric(errors='coerce') and then handle NaN deliberately (note NaN is also rejected downstream as non-finite).","Represent missing marks by omitting the date entirely rather than a placeholder.","For strings, strip separators: float(s.replace(',', ''))."],"exampleFix":"# before\ntwr = time_weighted_return([('2024-01-01', '1,050.00'), ('2024-12-31', '1,100.00')])  # raises\n\n# after\nclean = [(d, float(str(v).replace(',', ''))) for d, v in marks]\ntwr = time_weighted_return(clean)","handlingStrategy":"validation","validationCode":"clean = []\nfor d, v in valuations:\n    try:\n        clean.append((d, float(v)))\n    except (TypeError, ValueError):\n        continue  # or raise with contract/account context\n","typeGuard":"def all_values_numeric(vals) -> bool:\n    try:\n        return all(float(v) is not None for _, v in vals)\n    except (TypeError, ValueError):\n        return False","tryCatchPattern":"try:\n    r = time_weighted_return(valuations)\nexcept ValueError as e:\n    if 'must be numeric' in str(e):\n        raise MarkDataError(str(e)) from e\n    raise","preventionTips":["Coerce DB/CSV columns to float dtype at load time, surfacing errors.","Avoid locale-formatted strings; strip thousand separators explicitly.","Use dropna-and-log rather than placeholder strings for missing marks."],"tags":["performance","valuation","type-coercion","data-quality"],"backgroundTag":"non-numeric-input","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}