{"record":{"id":"868e99aa9ab5e5d8","repo":"HKUDS/Vibe-Trading","slug":"comps-total-debt-must-be-a-finite-number-got-to","errorCode":null,"errorMessage":"comps: total_debt must be a finite number, got {total_debt!r}","messagePattern":"comps: total_debt must be a finite number, got (.+?)","errorType":"exception","errorClass":"ValuationError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/valuation/comps.py","lineNumber":388,"sourceCode":"def _bridge_delta(\n    total_debt: float,\n    cash_and_equivalents: float,\n    minority_interest: float | None,\n    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}\"","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/valuation/comps.py#L370-L406","documentation":"The equity-to-enterprise-value bridge requires total_debt to be a finite number. _bridge_delta computes total_debt - cash plus optional components, so a NaN/inf debt would propagate into every EV and multiple downstream, hence the hard failure.","triggerScenarios":"Calling enterprise_value or equity_value_from_enterprise_value with total_debt=math.nan or float('inf'); often debt is summed from balance-sheet lines where one is NaN.","commonSituations":"Balance-sheet extraction returning NaN for a missing debt line; DataFrame sum over all-NaN columns yielding NaN; JSON nulls coerced to NaN by a numeric parser.","solutions":["Check the debt input: print total_debt before the call and locate the NaN/inf source.","Coerce missing debt lines to 0.0 only when you can justify zero debt, else supply a sourced estimate.","Add a finite guard in your data layer: if not math.isfinite(total_debt): raise/repair before calling."],"exampleFix":"# before\nev = enterprise_value(market_cap, total_debt=df['debt'].sum())  # NaN if column empty\n\n# after\ntotal_debt = float(df['debt'].sum() or 0.0)\nassert math.isfinite(total_debt)\nev = enterprise_value(market_cap, total_debt=total_debt)","handlingStrategy":"validation","validationCode":"import math\ntotal_debt = float(total_debt)\nassert math.isfinite(total_debt), total_debt","typeGuard":"def finite_float(v):\n    return isinstance(v, (int, float)) and math.isfinite(v)","tryCatchPattern":"try:\n    ev = enterprise_value(...)\nexcept ValuationError as e:\n    if 'total_debt' in str(e):\n        # repair or exclude the peer\n        ...","preventionTips":["Guard all bridge inputs with math.isfinite before the call","Coerce empty sums to 0.0 deliberately, not accidentally","Unit-test ingestion with NaN-laden fixtures"],"tags":["valuation","enterprise-value","nan","finite-check"],"backgroundTag":"nan-input-validation","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}