{"record":{"id":"8c483bf0bd013172","repo":"HKUDS/Vibe-Trading","slug":"index-levels-must-be-a-pandas-series-of-index-leve","errorCode":null,"errorMessage":"index_levels must be a pandas Series of index levels indexed by date, got {type(index_levels).__name__}","messagePattern":"index_levels must be a pandas Series of index levels indexed by date, got (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/fundmath.py","lineNumber":1364,"sourceCode":"\n    Args:\n        index_levels: Public-market index levels, a ``pandas.Series`` whose\n            index is date-like (``DatetimeIndex``, or labels accepted by\n            :func:`~src.entities.models.normalize_date`) and whose values are\n            the index's level on each date (a price or a total-return index\n            value, not a return).\n\n    Returns:\n        Mapping from ``datetime.date`` to the index level on that date.\n\n    Raises:\n        TypeError: If ``index_levels`` is not a ``pandas.Series``.\n        ValueError: If it is empty, a level is not finite and positive, or two\n            entries normalize to the same date (an ambiguous lookup, refused\n            rather than guessed at by taking the first or last).\n    \"\"\"\n    if not isinstance(index_levels, pd.Series):\n        raise TypeError(\n            \"index_levels must be a pandas Series of index levels indexed by \"\n            f\"date, got {type(index_levels).__name__}\"\n        )\n    if index_levels.empty:\n        raise ValueError(\n            \"index_levels is empty; a public market equivalent needs a \"\n            \"benchmark to compare against\"\n        )\n    lookup: dict[_dt.date, float] = {}\n    for raw_date, raw_level in index_levels.items():\n        day = normalize_date(raw_date, field_name=\"index_levels date\")\n        if day in lookup:\n            raise ValueError(\n                f\"index_levels has more than one entry for {day}; resolve the \"\n                \"duplicate before calling, rather than have this function \"\n                \"guess which one is authoritative\"\n            )\n        level = float(raw_level)","sourceCodeStart":1346,"sourceCodeEnd":1382,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/fundmath.py#L1346-L1382","documentation":"PME functions (ks_pme, pme_plus, direct_alpha) normalize the benchmark via _index_levels_by_date, which requires a pandas.Series indexed by date. Any other type (DataFrame, list, dict, ndarray) is rejected with a TypeError.","triggerScenarios":"Calling ks_pme(series, index_levels=[[date, level]]) or passing a DataFrame, dict {date: level}, or plain list of levels.","commonSituations":"Loading a benchmark CSV with pd.read_csv and forgetting to squeeze/select the single column; building levels as a list from an API response; passing a DataFrame column slice which yields a DataFrame on older pandas.","solutions":["Convert to a Series first: pd.Series(levels, index=pd.to_datetime(dates)) or df['level']","Use pd.read_csv(..., index_col=0, parse_dates=True)['close'] so you get a Series","Check type(index_levels) is pd.Series before the call"],"exampleFix":"# before\nks_pme(series, index_levels={d: lvl for d, lvl in rows})\n\n# after\nimport pandas as pd\nlevels = pd.Series([lvl for _, lvl in rows], index=pd.to_datetime([d for d, _ in rows]))\nks_pme(series, index_levels=levels)","handlingStrategy":"type-guard","validationCode":"assert isinstance(index_levels, pd.Series), type(index_levels)","typeGuard":"def is_date_indexed_series(x) -> bool:\n    return isinstance(x, pd.Series) and isinstance(x.index, pd.DatetimeIndex)","tryCatchPattern":null,"preventionTips":["Use pd.read_csv(..., index_col=0, parse_dates=True)[col] for benchmarks","Add a loader helper that always returns a Series"],"tags":["fund-math","pme","pandas","type-validation"],"backgroundTag":"wrong-argument-type","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}