{"record":{"id":"cb2f711cab9918c0","repo":"HKUDS/Vibe-Trading","slug":"index-levels-has-more-than-one-entry-for-day-re","errorCode":null,"errorMessage":"index_levels has more than one entry for {day}; resolve the duplicate before calling, rather than have this function guess which one is authoritative","messagePattern":"index_levels has more than one entry for (.+?); resolve the duplicate before calling, rather than have this function guess which one is authoritative","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/fundmath.py","lineNumber":1377,"sourceCode":"        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)\n        if not math.isfinite(level) or level <= 0.0:\n            raise ValueError(\n                f\"index level on {day} is {raw_level!r}; index levels must be \"\n                \"finite and positive to serve as a growth-factor denominator\"\n            )\n        lookup[day] = level\n    return lookup\n\n\ndef _index_level_at(\n    lookup: Mapping[_dt.date, float], day: _dt.date, *, flow_description: str\n) -> float:\n    \"\"\"Look up one date in an index lookup table, or fail loudly.","sourceCodeStart":1359,"sourceCodeEnd":1395,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/fundmath.py#L1359-L1395","documentation":"When building the date->level lookup, two index entries normalize to the same calendar date (e.g. timestamps '2024-03-01' and '2024-03-01 14:30'). The library refuses to guess which level is authoritative, so it raises instead of taking first/last.","triggerScenarios":"Passing an index_levels Series with intraday timestamps for the same day (hourly bars), or duplicated dates from concatenating overlapping data sources.","commonSituations":"Feeding daily OHLCV with a datetime index at 09:30/16:00; concatenating two benchmark files with overlapping periods; timezone shifts creating same-day duplicates.","solutions":["Resample to daily and take one value per day: levels.resample('1D').last().dropna()","Deduplicate: levels = levels[~index.duplicated(keep='last')] after normalizing dates","Drop the time component: levels.index = levels.index.normalize()"],"exampleFix":"# before\nks_pme(series, hourly_close_series)  # multiple entries per day\n\n# after\ndaily = hourly_close_series.resample(\"1D\").last().dropna()\nks_pme(series, daily)","handlingStrategy":"validation","validationCode":"levels = levels[~levels.index.duplicated(keep='last')]\nlevels.index = levels.index.normalize()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resample intraday benchmark data to daily before PME","Deduplicate concatenated benchmark sources"],"tags":["fund-math","pme","duplicate-dates","time-series"],"backgroundTag":"duplicate-data-keys","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}