{"record":{"id":"dfda950ae9acfd61","repo":"HKUDS/Vibe-Trading","slug":"comps-cash-and-equivalents-must-be-a-finite-numbe","errorCode":null,"errorMessage":"comps: cash_and_equivalents must be a finite number, got {cash_and_equivalents!r}","messagePattern":"comps: cash_and_equivalents must be a finite number, got (.+?)","errorType":"exception","errorClass":"ValuationError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/valuation/comps.py","lineNumber":392,"sourceCode":"    preferred_stock: float | None,\n    investments_in_associates: float | None,\n) -> tuple[float, tuple[str, ...]]:\n    \"\"\"Compute the EV-minus-equity-value delta and which optional items were omitted.\n\n    The delta is added to equity value to reach EV, and subtracted from EV to\n    reach equity value -- the two public bridge functions differ only in\n    which side is the known input.\n\n    Returns:\n        `(delta, omitted_components)`.\n    \"\"\"\n    omitted: list[str] = []\n    if not math.isfinite(total_debt):\n        raise ValuationError(\n            f\"comps: total_debt must be a finite number, got {total_debt!r}\"\n        )\n    if not math.isfinite(cash_and_equivalents):\n        raise ValuationError(\n            f\"comps: cash_and_equivalents must be a finite number, got {cash_and_equivalents!r}\"\n        )\n    total = total_debt - cash_and_equivalents\n    for name, value in (\n        (\"minority_interest\", minority_interest),\n        (\"preferred_stock\", preferred_stock),\n        (\"investments_in_associates\", investments_in_associates),\n    ):\n        if value is None:\n            omitted.append(name)\n            continue\n        if not math.isfinite(value):\n            raise ValuationError(\n                f\"comps: {name} must be a finite number, got {value!r}\"\n            )\n        sign = -1.0 if name == \"investments_in_associates\" else 1.0\n        total += sign * value\n    return total, tuple(omitted)","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/valuation/comps.py#L374-L410","documentation":"The EV bridge requires cash_and_equivalents to be finite. Since cash is subtracted from debt to get net debt, NaN cash would corrupt the bridge in both directions (EV and implied equity).","triggerScenarios":"Calling enterprise_value / equity_value_from_enterprise_value with cash_and_equivalents=math.nan or float('inf'), e.g. a missing cash figure parsed into NaN.","commonSituations":"Missing cash line in scraped or API-fetched balance sheets; pandas operations (mean of empty series) returning NaN; unit-conversion bugs producing inf.","solutions":["Print/validate cash_and_equivalents before the bridge call and trace where NaN came from.","Substitute a justified value (0.0 or sourced cash figure) once confirmed.","Add ingestion-time finite checks for all bridge inputs."],"exampleFix":"# before\nev = enterprise_value(market_cap, total_debt, cash)  # cash = nan\n\n# after\ncash = 0.0 if cash is None or not math.isfinite(cash) else float(cash)\nev = enterprise_value(market_cap, total_debt, cash)","handlingStrategy":"validation","validationCode":"import math\ncash = 0.0 if cash is None else float(cash)\nif not math.isfinite(cash):\n    raise ValueError(f'cash not finite: {cash!r}')","typeGuard":null,"tryCatchPattern":"except ValuationError as e:\n    if 'cash_and_equivalents' in str(e):\n        cash = 0.0  # documented fallback\n        ev = enterprise_value(market_cap, total_debt, cash)","preventionTips":["Treat missing cash as an explicit 0.0 decision, never NaN","Validate extracted balance-sheet lines for finiteness"],"tags":["valuation","enterprise-value","cash","nan"],"backgroundTag":"nan-input-validation","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}