使用 load_table_from_dataframe() 存储带有日期时间对象的数据帧时的模式冲突

Schema conflict when storing dataframes with datetime objects using load_table_from_dataframe()

我正在尝试将数据从 Pandas DataFrame 加载到 BigQuery table。 DataFrame 有一列 dtype datetime64[ns],当我尝试使用 load_table_from_dataframe() 存储 df 时,我得到

google.api_core.exceptions.BadRequest: 400 Provided Schema does not match Table [table name]. Field computation_triggered_time has changed type from DATETIME to TIMESTAMP.

table 的架构显示为

CREATE TABLE `[table name]` (
  ...
  computation_triggered_time    DATETIME  NOT NULL,
  ...
)

DataFrame 中,computation_triggered_timedatetime64[ns] 列。当我从 CSV 中读取原始 DataFrame 时,我将它从文本转换为日期时间,如下所示:

df['computation_triggered_time'] = \ 
  df.to_datetime(df['computation_triggered_time']).values.astype('datetime64[ms]')

注:

.values.astype('datetime64[ms]') 部分是必需的,因为 load_table_from_dataframe() 使用 PyArrow 序列化 df,如果数据具有纳秒级精度,则失败。错误类似于

[...] Casting from timestamp[ns] to timestamp[ms] would lose data

这看起来像是 Google 的 google-cloud-python 包的问题,​​您可以在那里报告错误吗? https://github.com/googleapis/google-cloud-python