{"record":{"id":"10f7ebb7e6c13229","repo":"HKUDS/Vibe-Trading","slug":"model-name-must-be-a-finite-number-got-val","errorCode":null,"errorMessage":"{model}: {name} must be a finite number, got {val!r}","messagePattern":"(.+?): (.+?) must be a finite number, got (.+?)","errorType":"exception","errorClass":"ValuationError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/valuation/comps.py","lineNumber":273,"sourceCode":"        ValuationError: If `policy` is not one of `CALENDARISATION_POLICIES`,\n            or if any supplied period value is not a finite number.\n        MissingInputError: If `periods` lacks a field this policy needs.\n    \"\"\"\n    if policy not in CALENDARISATION_POLICIES:\n        raise ValuationError(\n            f\"comps.calendarise_metric: unknown policy {policy!r}, must be \"\n            f\"one of {CALENDARISATION_POLICIES}\"\n        )\n    model = f\"comps.calendarise_metric[{company_name}.{metric_name}:{policy}]\"\n\n    for name, val in (\n        (\"last_full_fiscal_year\", periods.last_full_fiscal_year),\n        (\"current_year_to_date\", periods.current_year_to_date),\n        (\"prior_year_to_date\", periods.prior_year_to_date),\n        (\"next_full_fiscal_year\", periods.next_full_fiscal_year),\n    ):\n        if val is not None and not math.isfinite(val):\n            raise ValuationError(\n                f\"{model}: {name} must be a finite number, got {val!r}\"\n            )\n\n    if policy == \"ltm\":\n        require_inputs(\n            {\n                \"last_full_fiscal_year\": periods.last_full_fiscal_year,\n                \"current_year_to_date\": periods.current_year_to_date,\n                \"prior_year_to_date\": periods.prior_year_to_date,\n            },\n            (\"last_full_fiscal_year\", \"current_year_to_date\", \"prior_year_to_date\"),\n            model,\n        )\n        value = (\n            periods.last_full_fiscal_year\n            + periods.current_year_to_date\n            - periods.prior_year_to_date\n        )","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/valuation/comps.py#L255-L291","documentation":"calendarise_metric validates that every fiscal-period value it uses to calendarise a metric (last_full_fiscal_year, current_year_to_date, prior_year_to_date, next_full_fiscal_year) is a finite number before combining them under an LTM/NTM policy. NaN or infinity in any period would silently poison the blended figure, so the library refuses it.","triggerScenarios":"Calling run_comps / peer_multiple_set where a peer or target's fiscal periods dict contains math.nan, float('inf'), or a numpy NaN for any period key; typically the data came from a pandas frame or JSON with missing values coerced to NaN.","commonSituations":"Loading peer financials from CSV/DataFrame where missing cells become NaN; joining data sources that emit nulls; upstream arithmetic producing inf (division by zero) that is fed straight into fiscal periods.","solutions":["Find which period value is non-finite: log the peer name and the four period values before calling run_comps.","Drop or repair peers with NaN/inf periods (fillna with sourced estimates or exclude the peer).","Guard your ingestion layer: math.isfinite check per numeric field before constructing fiscal periods.","If NaN means 'not reported', pass None instead so calendarise_metric treats it as missing rather than invalid."],"exampleFix":"# before\nperiods = {\"last_full_fiscal_year\": df.iloc[0][\"fy_revenue\"], ...}  # may be NaN\n\n# after\nimport math\nperiods = {k: (v if v is None or math.isfinite(v) else None) for k, v in raw_periods.items()}","handlingStrategy":"validation","validationCode":"import math\nfor name, v in periods.items():\n    if v is not None and not math.isfinite(v):\n        raise ValueError(f'non-finite period {name}: {v!r}')","typeGuard":"def has_finite_periods(p):\n    return all(v is None or (isinstance(v, (int, float)) and math.isfinite(v)) for v in p.values())","tryCatchPattern":"from quantlib.valuation.contracts import ValuationError\ntry:\n    run_comps(target, peers, policy)\nexcept ValuationError as e:\n    if 'must be a finite number' in str(e):\n        log.warning('dropping peer with non-finite periods: %s', e)\n    raise","preventionTips":["Sanitize fiscal-period dicts with math.isfinite before constructing peers","Map missing values to None, not NaN","Add DataFrame dropna/finite filters on numeric columns at ingestion"],"tags":["valuation","nan","finite-check","comps","input-validation"],"backgroundTag":"nan-input-validation","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}