Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: convert datetime64[us] to datetime64[ns] for TIMESTAMP and DATETIME #858

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kitagry
Copy link

@kitagry kitagry commented Jan 19, 2025

Fixes #852

In the document, pandas-gbq returns datetime64[ns] or object, but in pandas2, it returns datetime64[us].

https://googleapis.dev/python/pandas-gbq/latest/reading.html#inferring-the-dataframe-s-dtypes

image

@kitagry kitagry requested review from a team as code owners January 19, 2025 07:19
@kitagry kitagry requested a review from tswast January 19, 2025 07:19
@product-auto-label product-auto-label bot added the size: s Pull request size is small. label Jan 19, 2025
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery-pandas API. label Jan 19, 2025
and pandas.api.types.is_datetime64_dtype(df[name])
and not pandas.api.types.is_datetime64_ns_dtype(df[name])
):
df[name] = df[name].dt.as_unit("ns")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd actually prefer we use us as the units where possible. Technically, ns can cause data loss, as BigQuery stores its DATETIME/TIMESTAMP values with microsecond precision.

Could we update the documentation, instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery-pandas API. size: s Pull request size is small.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Timestamp returns a different type depending on whether the data is empty or not.
3 participants