{"record":{"id":"089cbe31abafca0d","repo":"HKUDS/Vibe-Trading","slug":"valuations-index-value-must-be-finite","errorCode":null,"errorMessage":"valuations[{index}].value must be finite","messagePattern":"valuations\\[(.+?)\\]\\.value must be finite","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/tools/cashflow_analytics_tool.py","lineNumber":332,"sourceCode":"            or an entry lacks a usable date or value.\n    \"\"\"\n    if not isinstance(raw, list) or len(raw) < 2:\n        raise ValueError(\"valuations must be an array of at least two {date, value} objects\")\n    if len(raw) > _MAX_VALUATIONS:\n        raise ValueError(f\"valuations may contain at most {_MAX_VALUATIONS} entries\")\n\n    pairs: list[tuple[date, float]] = []\n    for index, item in enumerate(raw):\n        if not isinstance(item, dict):\n            raise ValueError(f\"valuations[{index}] must be an object with date and value\")\n        if \"date\" not in item or \"value\" not in item:\n            raise ValueError(f\"valuations[{index}] needs both 'date' and 'value'\")\n        try:\n            value = float(item[\"value\"])\n        except (TypeError, ValueError) as exc:\n            raise ValueError(f\"valuations[{index}].value must be numeric\") from exc\n        if not math.isfinite(value):\n            raise ValueError(f\"valuations[{index}].value must be finite\")\n        pairs.append((item[\"date\"], value))\n    return pairs\n\n\ndef _resolve_flows(kwargs: dict[str, Any]) -> CashFlowSeries | None:\n    \"\"\"Build the cash-flow series from inline records or from a file.\n\n    Args:\n        kwargs: The tool's raw inputs.\n\n    Returns:\n        A ``CashFlowSeries``, or ``None`` when no flows were supplied.\n\n    Raises:\n        ValueError: If both sources were given, an inline record is malformed,\n            or a currency is missing. File problems surface as\n            ``CashFlowIngestError``, which is a ``ValueError``.\n    \"\"\"","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/tools/cashflow_analytics_tool.py#L314-L350","documentation":"Raised when a valuation's value coerces to a float that is not finite (NaN, +inf, -inf, per math.isfinite). Infinite or NaN results poison every downstream statistic, so the tool rejects them upfront.","triggerScenarios":"valuations=[{\"date\": \"2024-01-01\", \"value\": \"NaN\"}] or value=\"Infinity\" (float() accepts these strings in Python), or a computed value that overflowed to inf before being passed in.","commonSituations":"Aggregations that divided by zero upstream, pandas/NumPy pipelines emitting NaN for missing data then serializing to JSON, or literal 'NaN'/'Infinity' tokens in JSON payloads (Python json.loads accepts them).","solutions":["Filter out non-finite values before calling the tool (e.g. filter out NaN from pandas series with .dropna())","Fix the upstream division-by-zero or overflow producing inf/NaN","Use json.dumps(..., allow_nan=False) upstream to catch these at serialization time"],"exampleFix":"# before\nvaluations = series.to_dict()  # may include NaN\n# after\nvaluations = [{\"date\": d, \"value\": float(v)} for d, v in series.dropna().items()]","handlingStrategy":"validation","validationCode":"import math\nvaluations = [v for v in valuations if math.isfinite(float(v[\"value\"]))]","typeGuard":"import math\n\ndef is_finite_value(item: dict) -> bool:\n    try:\n        return math.isfinite(float(item[\"value\"]))\n    except (TypeError, ValueError):\n        return False","tryCatchPattern":null,"preventionTips":["dropna() pandas series before serialization","Use allow_nan=False in json.dumps upstream to fail early","Guard upstream divisions against zero"],"tags":["cashflow-analytics","valuations","nan-infinity","python"],"backgroundTag":"non-finite-value-rejected","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}