fix: clear AlphaVantage fetcher index name to avoid 'date' ambiguity (#1351)

_fetch_raw_data 中 `df.index = pd.to_datetime(df['date'])` 会让
DatetimeIndex 继承源 Series 的 name='date',随后 _normalize_data
重新添加 'date' 列时与索引 level 同名,导致 pandas 在
sort_values('date') 处抛出 ValueError。

复现:load_history_df('AAPL') 走 AlphaVantage 通道时返回 0 行,
报错 "'date' is both an index level and a column label"。

修复:assign 索引后立刻清空 index.name,下游可无歧义引用 'date' 列。
影响范围仅 data_provider/alphavantage_fetcher.py 一行,
其他数据源链路未触及。

Co-authored-by: 贞元 <zhenyuan.wql@alibaba-inc.com>
This commit is contained in:
wqlC
2026-05-19 22:00:12 +08:00
committed by GitHub
parent c65972642c
commit 5029605efa

View File

@@ -89,6 +89,7 @@ class AlphaVantageFetcher(BaseFetcher):
df = pd.DataFrame(rows)
df.index = pd.to_datetime(df['date'])
df.index.name = None # 避免与 _normalize_data 重新添加的 'date' 列冲突
return df.drop(columns=['date'])
def _normalize_data(self, df: pd.DataFrame, stock_code: str) -> pd.DataFrame: