修复 NaN 值导致 JSON 序列化失败、K 线数据无法展示
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -68,6 +68,11 @@ def save_candles(df: pd.DataFrame, db_url: str = DEFAULT_DB_URL):
|
||||
df = df.copy()
|
||||
df = df.where(pd.notna(df), None)
|
||||
records = df.to_dict(orient="records")
|
||||
# pandas float 列的 None 会被转为 NaN,需手动清理后再存入数据库
|
||||
for record in records:
|
||||
for key, val in record.items():
|
||||
if isinstance(val, float) and val != val: # NaN != NaN
|
||||
record[key] = None
|
||||
with conn.cursor() as cur:
|
||||
cur.executemany(
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user