Skip to content

to_gbq fails when trying to save a Pandas datetime64[ns] to a BQ DATE field #362

Closed
@swt2c

Description

@swt2c
Traceback (most recent call last):
  File "/tmp/test-bq_20210416_36390b15/test_bq.py", line 8, in <module>
    df.to_gbq(
  File "/opt/conda/default/lib/python3.8/site-packages/pandas/core/frame.py", line 1710, in to_gbq
    gbq.to_gbq(
  File "/opt/conda/default/lib/python3.8/site-packages/pandas/io/gbq.py", line 211, in to_gbq
    pandas_gbq.to_gbq(
  File "/opt/conda/default/lib/python3.8/site-packages/pandas_gbq/gbq.py", line 1093, in to_gbq
    connector.load_data(
  File "/opt/conda/default/lib/python3.8/site-packages/pandas_gbq/gbq.py", line 580, in load_data
    self.process_http_error(ex)
  File "/opt/conda/default/lib/python3.8/site-packages/pandas_gbq/gbq.py", line 380, in process_http_error
    raise GenericGBQException("Reason: {0}".format(ex))
pandas_gbq.gbq.GenericGBQException: Reason: 400 Error while reading data, error message: Could not parse '2021-04-17 00:00:00.000000' as DATE for field for_date (position 1) starting at location 0  with message 'Unable to parse'

I seem to be able to work around this by forcing the datetime64[ns] column to the .dt.date of the datetime64, but it seems like pandas-gbq should be able to figure this out when I supply the schema with a 'DATE' column in it.

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.api: bigqueryIssues related to the googleapis/python-bigquery-pandas API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions