fix(factors/engine): 修复列选择时基础列重复的问题

This commit is contained in:
2026-03-11 00:12:05 +08:00
parent e6c3a918c7
commit f3b3560d26
2 changed files with 1692 additions and 350 deletions

File diff suppressed because one or more lines are too long

View File

@@ -262,10 +262,11 @@ class DataRouter:
if stock_codes is not None:
df = df.filter(pl.col("ts_code").is_in(stock_codes))
# 选择需要的列
select_cols = ["ts_code", "trade_date"] + [
c for c in columns if c in df.columns
]
# 选择需要的列(避免重复)
base_cols = ["ts_code", "trade_date"]
extra_cols = [c for c in columns if c in df.columns and c not in base_cols]
select_cols = base_cols + extra_cols
return df.select(select_cols)
def _load_from_database(
@@ -314,10 +315,10 @@ class DataRouter:
if col not in df.columns and col not in ["ts_code", "trade_date"]:
raise ValueError(f"{table_name} 缺少字段: {col}")
# 选择需要的列
select_cols = ["ts_code", "trade_date"] + [
c for c in columns if c in df.columns
]
# 选择需要的列(避免重复)
base_cols = ["ts_code", "trade_date"]
extra_cols = [c for c in columns if c in df.columns and c not in base_cols]
select_cols = base_cols + extra_cols
return df.select(select_cols)