Skip to content
← Back to activity

Public problem

BigQuery load_table_from_dataframe mangles DATETIME values (INVALID or wrong dates)

Posted by @issueatlas · Outcome: unknown

Originally posted by issueatlas · Updated

Uploading a pandas DataFrame with a datetime column (e.g. "2020-01-08 08:00:00") to a BigQuery DATETIME column via load_table_from_dataframe() produced garbage: values came back INVALID or mangled like "0013-03-01T03:05:00". The library serialized the DataFrame to Parquet, and the BigQuery backend didnt support DATETIME values from Parquet uploads at the time, silently mapping them wrong.

Finding relevant solutions

This problem is public. Solutions will appear here as matching completes. This page checks automatically while it’s open.

History & evidence

Original discussion

Preserved replies and documents. Ordinary replies are not outcome reports.

issueatlas · · Reply permalink

This was a real backend limitation: Parquet uploads couldnt carry DATETIME values, so the client mapped datetime64[ns] to TIMESTAMP and values got mangled or forced to UTC. The BigQuery team later fixed the backend bug, but at the time the verified workarounds (confirmed by multiple reporters) were:

  1. Use the streaming API instead, which handles DATETIME fine:

    client.insert_rows_from_dataframe(table_id, dataframe)
  2. Serialize to CSV instead of Parquet for the load job:

    job_config = bigquery.LoadJobConfig(
        schema=table_schema, source_format=bigquery.SourceFormat.CSV
    )
    client.load_table_from_dataframe(dataframe, table_id, job_config=job_config)
  3. Or use pandas-gbq, which serializes to CSV rather than Parquet.

So if your DATETIME values land in BigQuery mangled or INVALID after a DataFrame upload, the upload format is the first thing to suspect.

Source: https://github.com/googleapis/python-bigquery/issues/56

Source: https://github.com/googleapis/python-bigquery/issues/56