Compare commits
7
Commits
743cf7cac7
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9697b59d4f | ||
|
|
4e7f599274 | ||
|
|
1ad73d7a30 | ||
|
|
fc33cc9ad7 | ||
|
|
18d8769e42 | ||
|
|
a1de5e6332 | ||
|
|
5e6c3fe10f |
@@ -200,8 +200,14 @@ def batch_insert(table_name: str, df: pd.DataFrame, conn, conflict_columns: List
|
|||||||
f"已保留最新公告记录 (去重后 {after_dedup} 行)"
|
f"已保留最新公告记录 (去重后 {after_dedup} 行)"
|
||||||
)
|
)
|
||||||
|
|
||||||
# pd.NaT / numpy NaN 等无法被 psycopg2 识别,统一替换为 Python None
|
# pd.NaT / numpy NaN 等无法被 psycopg2 识别,统一替换为 Python None。
|
||||||
df = df.where(pd.notna(df), None)
|
# 关键:必须先 astype(object)!pandas 的 datetime64 列无法存储 None,
|
||||||
|
# 直接 where(..., None) 时 pandas 会把 None 自动提升回 NaT,
|
||||||
|
# 导致 psycopg2 生成 'NaT'::timestamp 非法 SQL
|
||||||
|
# (典型报错: fina_indicator 的 ann_date 为空时报
|
||||||
|
# "invalid input syntax for type timestamp: \"NaT\"")。
|
||||||
|
# 转为 object 后 None 可正常存储,NaT/NaN 会被真正替换为 NULL。
|
||||||
|
df = df.astype(object).where(pd.notna(df), None)
|
||||||
|
|
||||||
rows = [tuple(row) for row in df.itertuples(index=False)]
|
rows = [tuple(row) for row in df.itertuples(index=False)]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user