Skip to content

BigQuery: Converting query results to dataframe fails to convert date columns #136

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

Closed
darwinyip opened this issue Jun 12, 2020 · 3 comments
Assignees
Labels
api: bigquery Issues related to the googleapis/python-bigquery API. type: question Request for information or clarification. Not an issue.

Comments

@darwinyip
Copy link

Environment details

google-api-python-client==1.9.3
google-cloud-bigquery==1.25.0
pyarrow==0.17.1

Steps to reproduce

  1. Issuing a select statement that returns a date column and converting the results to dataframe fails to convert the date column and leaves it as string

Code example

select = "select DATE(date) as dt from [project:dataset.table]"
client = bigquery.Client()
job_config = bigquery.QueryJobConfig(use_legacy_sql=True)
select_job = client.query(select, job_config=job_config)
select_job.result()
df = select_job.to_dataframe()
df.dtypes

# dt    object
@meredithslota meredithslota transferred this issue from googleapis/google-cloud-python Jun 12, 2020
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Jun 12, 2020
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Jun 13, 2020
@HemangChothani HemangChothani self-assigned this Jun 15, 2020
@HemangChothani HemangChothani added type: question Request for information or clarification. Not an issue. and removed triage me I really want to be triaged. labels Jun 15, 2020
@HemangChothani
Copy link
Contributor

@darwinyip Could you try to set the dtypes argument to to_dataframe. We don't have any logic to convert from the API response types to pandas dtypes unless the dtypes argument is specified.

Example:

 expected_dtype = {cloumn_name:dtype}    # e.x: dtype = 'datetime64[ns]'
 df = select_job.to_dataframe(dtypes=expected_dtype)

 df.dtypes["column_name"].name   #check dtype of cloumn

The duplicate issue of #11

@darwinyip
Copy link
Author

Manually setting the dtype works but it's not a very friendly user experience.

@HemangChothani
Copy link
Contributor

@darwinyip Could you please comment on issue #11 as this is the duplicate issue and discussion is going on that thread so you can get better and faster reply, I have already linked and mentioned your comment there so closing this issue.

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 API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants