{"record":{"id":"b575081784670034","repo":"HKUDS/Vibe-Trading","slug":"returns-contains-no-finite-observation","errorCode":null,"errorMessage":"returns contains no finite observation","messagePattern":"returns contains no finite observation","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/risk.py","lineNumber":95,"sourceCode":"    \"\"\"Coerce a return series to a finite 1-D float array.\n\n    Args:\n        returns: Return observations as a pandas Series, numpy array or any\n            sequence of floats. NaN and infinite values are dropped.\n\n    Returns:\n        A 1-D float64 array of the finite observations, in input order.\n\n    Raises:\n        ValueError: If the input is not 1-D or holds no finite observation.\n    \"\"\"\n    values = np.asarray(returns, dtype=float)\n    if values.ndim > 1:\n        raise ValueError(f\"returns must be 1-D, got shape {values.shape}\")\n    values = values.ravel()\n    finite = values[np.isfinite(values)]\n    if finite.size == 0:\n        raise ValueError(\"returns contains no finite observation\")\n    return finite\n\n\ndef _validate_confidence(confidence: float) -> None:\n    \"\"\"Check that a confidence level is a strict probability.\n\n    Args:\n        confidence: Confidence level, e.g. 0.95.\n\n    Raises:\n        ValueError: If ``confidence`` is not strictly between 0 and 1.\n    \"\"\"\n    if not 0.0 < confidence < 1.0:\n        raise ValueError(f\"confidence must be in (0, 1), got {confidence}\")\n\n\ndef _validate_horizon(horizon: int) -> None:\n    \"\"\"Check that a holding period is a positive whole number of periods.","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/risk.py#L77-L113","documentation":"Raised by _clean_returns when the returns series passed to a risk statistic (historical_var, parametric_var, historical_cvar, fit_gpd_tail) contains zero finite values — i.e. it is empty, or every element is NaN/inf. The library requires at least one finite observation to compute any tail statistic, so it fails fast rather than returning NaN.","triggerScenarios":"Calling historical_var([], 0.95), parametric_var([np.nan]*10), or fit_gpd_tail with a series of all-NaN (e.g. a price series diff'd after leading NaNs, or an empty dataframe column).","commonSituations":"Loading a CSV with wrong column name (all NaN), a pandas pipeline that produced an empty slice (e.g. df[df.date > max_date]), or forward-filled price data turned into returns where the NaN row was not dropped.","solutions":["Check the input series length and np.isfinite(values).sum() before calling the risk function","Drop NaN/inf rows: returns = pd.Series(returns).replace([np.inf,-np.inf], np.nan).dropna()","Log the series head/dtype to find the upstream pipeline stage that emptied it","If an empty input is legitimate in your flow, guard with a length check and skip or return NaN explicitly"],"exampleFix":"// before\nvar = historical_var(returns, confidence=0.95)  # returns is all NaN\n// after\nreturns = pd.Series(returns).replace([np.inf, -np.inf], np.nan).dropna()\nvar = historical_var(returns, confidence=0.95) if len(returns) else float(\"nan\")","handlingStrategy":"validation","validationCode":"import numpy as np\ndef finite_returns_ok(r):\n    v = np.asarray(r, dtype=float).ravel()\n    return np.isfinite(v).sum() > 0\n# call only when finite_returns_ok(returns)","typeGuard":"def has_finite_returns(returns) -> bool:\n    import numpy as np\n    v = np.asarray(returns, dtype=float).ravel()\n    return bool(np.isfinite(v).any())","tryCatchPattern":"try:\n    var = historical_var(returns, 0.95)\nexcept ValueError as e:\n    if \"no finite observation\" in str(e):\n        logger.warning(\"empty return series; skipping VaR\")\n        var = float(\"nan\")\n    else:\n        raise","preventionTips":["Drop NaN/inf from return series at ingest time","Assert a minimum series length before computing risk stats","Unit-test pipelines with empty and all-NaN inputs"],"tags":["quantlib","risk","validation","nan","valueerror"],"backgroundTag":"empty-or-nan-input-data","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}