GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix!: use nullable `Int64` and `boolean` dtypes in `to_dataframe` by tswast · Pull Request #786 · googleapis/python-bigquery

This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Conversation

@tswast

@tswast tswast commented Jul 20, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

To override this behavior, specify the types for the desired columns with the
dtype argument.

BREAKING CHANGE: uses Int64 type by default to avoid loss-of-precision in results with large integer values

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes https://issuetracker.google.com/144712110 🦕
Fixes #793

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tswast
feat!: use nullable types like float and Int64 by default in `to_data…
76d88f4
…frame`

To override this behavior, specify the types for the desired columns with the
`dtype` argument.
@tswast
tswast requested review from a team and stephaniewang526 and removed request for a team July 20, 2021 21:11
@product-auto-label product-auto-label Bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Jul 20, 2021
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Jul 20, 2021
@tswast
tswast marked this pull request as draft July 20, 2021 21:11
@tswast
tswast removed request for a team and stephaniewang526 July 20, 2021 21:12
@tswast

tswast commented Jul 20, 2021

Copy link
Copy Markdown
Contributor Author

I'll take a closer look at #776 before finishing this one, as it might mean fewer code paths to cover. I think the BQ Storage API will always be used for to_dataframe after that PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tswast tswast mentioned this pull request Jul 21, 2021
feat: use geopandas for GEOGRAPHY columns if geopandas is installed #792
Closed
@tswast
add test data for all scalar columns
f2223e9
@tswast

tswast commented Jul 21, 2021

Copy link
Copy Markdown
Contributor Author

I did a little bit of experimentation to see what the intermediate pyarrow.Table types are for both REST and BQ Storage API on all scalar types. They do align, so that's good. Also, floating points appear to be handled correctly, even with null values in the table.

It appears https://issuetracker.google.com/144712110 was fixed for FLOAT columns in #314 as of google-cloud-bigquery >= 2.2.0 (That was technically a breaking change [oops])

I might still keep this open so that we can have some explicit tests for different data types. Also, we're relying on PyArrow -> Pandas to pick the right data types, so maybe there's some dtype defaults we can help with still.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tswast tswast mentioned this pull request Jul 21, 2021
use pandas Int64 type by default to avoid precision loss #793
Closed
tswast added 2 commits July 21, 2021 16:36
@tswast
add test data for all scalar columns
07ed871
@tswast
Merge branch 'b144712110-nullable-pandas-types' of github.com:tswast/…
66ce732
…python-bigquery into b144712110-nullable-pandas-types
@tswast tswast changed the title feat!: use nullable types like float and Int64 by default in to_dataframe feat!: use nullable Int64 dtype by default in to_dataframe Jul 21, 2021
@tswast tswast changed the title feat!: use nullable Int64 dtype by default in to_dataframe fix!: use nullable Int64 dtype by default in to_dataframe Jul 21, 2021
tswast added 2 commits July 22, 2021 17:07
@tswast
update tests with expected dtypes
21d4369
@tswast
add expected types, REST test
69a747f
@tswast tswast mentioned this pull request Jul 23, 2021
to_dataframe dtypes argument could allow functions that take pandas.Series-like object and return new series #807
Closed
@tswast
use dtype defaults for "easy" cases
4f78e6d
@tswast tswast mentioned this pull request Jul 26, 2021
to_dataframe fails with Decimal type with precision 77 does not fit when REST API is used to download extreme BIGNUMERIC values #812
Closed
@plamut plamut added the semver: major Hint for users that this is an API breaking change. label Jul 27, 2021
@tswast
tswast changed the base branch from master to v3.x.x July 27, 2021 17:07
@tswast
tswast changed the base branch from v3.x.x to v3 July 27, 2021 17:27
tswast added 3 commits July 27, 2021 16:51
@tswast
Merge remote-tracking branch 'upstream/v3' into b144712110-nullable-p…
62a57bd
…andas-types
@tswast
add interval
d53aa68
@tswast
Merge remote-tracking branch 'upstream/v3' into b144712110-nullable-p…
d17e637
…andas-types
tswast added 3 commits August 6, 2021 17:01
@tswast
WIP: split TIME and DATE into separate issues
6ceff2c
@tswast
WIP: unit tests
18152d9
@tswast
add tests, update minimum pandas version
2e957cd
@tswast
tswast marked this pull request as ready for review August 9, 2021 20:05
@tswast tswast changed the title fix!: use nullable Int64 dtype by default in to_dataframe fix!: use nullable Int64 and boolean dtype by default in to_dataframe Aug 9, 2021
@tswast tswast changed the title fix!: use nullable Int64 and boolean dtype by default in to_dataframe fix!: use nullable Int64 and boolean dtypes in to_dataframe Aug 9, 2021
tswast
tswast commented Aug 11, 2021
View reviewed changes
Comment thread google/cloud/bigquery/_pandas_helpers.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@tswast
add unit test for repeated fields
8f90c51
@tswast

tswast commented Aug 11, 2021

Copy link
Copy Markdown
Contributor Author

Re: system test failure:

_____________ TestBigQuery.test_load_avro_from_uri_then_dump_table _____________
.
.
.
E   google.api_core.exceptions.RetryError: Deadline of 120.0s exceeded while calling functools.partial(<bound method PollingFuture._done_or_raise of <google.cloud.bigquery.job.load.LoadJob object at 0x7ff6eae07f40>>), last exception:

Didn't we increase the default deadline to 10 minutes? Maybe v3 branch needs a sync?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tswast
tswast requested a review from plamut August 11, 2021 16:45
@plamut
Merge branch 'v3' into b144712110-nullable-pandas-types
187a950
plamut
plamut approved these changes Aug 13, 2021
View reviewed changes

@plamut plamut left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Two nits, but not essential, looks good.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread docs/usage/pandas.rst
pip install --upgrade pandas

Alternatively, you can install the BigQuery python client library with
Alternatively, you can install the BigQuery Python client library with

@plamut plamut Aug 13, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

(nit)
Since already at this, there's at least on other occurrence of "python" not capitalized (line 69), which can also be fixed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google/cloud/bigquery/_pandas_helpers.py Outdated
loss-of-precision.

Returns:
Dict[str, str]: mapping from column names to dtypes

@plamut plamut Aug 13, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

(nit) Can be expressed as the annotation of the function return type.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
tswast added 2 commits August 16, 2021 10:07
@tswast
Address docs nits
3155dab
@tswast
Merge remote-tracking branch 'origin/b144712110-nullable-pandas-types…
189404c
…' into b144712110-nullable-pandas-types
tswast
tswast commented Aug 16, 2021
View reviewed changes
Comment thread tests/system/test_pandas.py
("max_results",), ((None,), (10,),) # Use BQ Storage API. # Use REST API.
)
def test_list_rows_nullable_scalars_dtypes(bigquery_client, scalars_table, max_results):
df = bigquery_client.list_rows(

@tswast tswast Aug 16, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Note to self: I'll need to exclude the INTERVAL column next time we sync with master

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tswast tswast added the automerge Merge the pull request once unit tests and other checks pass. label Aug 16, 2021
@tswast tswast mentioned this pull request Aug 16, 2021
chore: sync v3 with master branch #880
Merged
2 tasks done
@gcf-merge-on-green
gcf-merge-on-green Bot merged commit dcd78c7 into googleapis:v3 Aug 16, 2021
@gcf-merge-on-green gcf-merge-on-green Bot removed the automerge Merge the pull request once unit tests and other checks pass. label Aug 16, 2021
@tswast
tswast deleted the b144712110-nullable-pandas-types branch August 16, 2021 15:44
@tswast tswast mentioned this pull request Sep 8, 2021
Support for string[pyarrow] dtype #954
Closed
@tswast tswast mentioned this pull request Mar 29, 2022
fix!: remove out-of-date BigQuery ML protocol buffers #1178
Merged
4 tasks
tswast added a commit that referenced this pull request Mar 29, 2022
@tswast
fix!: remove out-of-date BigQuery ML protocol buffers (#1178)
76d88fb
deps!: BigQuery Storage and pyarrow are required dependencies (#776)

fix!: use nullable `Int64` and `boolean` dtypes in `to_dataframe` (#786) 

feat!: destination tables are no-longer removed by `create_job` (#891)

feat!: In `to_dataframe`, use `dbdate` and `dbtime` dtypes from db-dtypes package for BigQuery DATE and TIME columns (#972)

fix!: automatically convert out-of-bounds dates in `to_dataframe`, remove `date_as_object` argument (#972)

feat!: mark the package as type-checked (#1058)

feat!: default to DATETIME type when loading timezone-naive datetimes from Pandas (#1061)

feat: add `api_method` parameter to `Client.query` to select `INSERT` or `QUERY` API (#967)

fix: improve type annotations for mypy validation (#1081)

feat: use `StandardSqlField` class for `Model.feature_columns` and `Model.label_columns` (#1117)

docs: Add migration guide from version 2.x to 3.x (#1027)

Release-As: 3.0.0
@release-please release-please Bot mentioned this pull request Mar 29, 2022
chore(main): release 3.0.0 #1179
Merged
waltaskew pushed a commit to waltaskew/python-bigquery that referenced this pull request Jul 20, 2022
@tswast @waltaskew
fix!: remove out-of-date BigQuery ML protocol buffers (googleapis#1178)
e049810
deps!: BigQuery Storage and pyarrow are required dependencies (googleapis#776)

fix!: use nullable `Int64` and `boolean` dtypes in `to_dataframe` (googleapis#786) 

feat!: destination tables are no-longer removed by `create_job` (googleapis#891)

feat!: In `to_dataframe`, use `dbdate` and `dbtime` dtypes from db-dtypes package for BigQuery DATE and TIME columns (googleapis#972)

fix!: automatically convert out-of-bounds dates in `to_dataframe`, remove `date_as_object` argument (googleapis#972)

feat!: mark the package as type-checked (googleapis#1058)

feat!: default to DATETIME type when loading timezone-naive datetimes from Pandas (googleapis#1061)

feat: add `api_method` parameter to `Client.query` to select `INSERT` or `QUERY` API (googleapis#967)

fix: improve type annotations for mypy validation (googleapis#1081)

feat: use `StandardSqlField` class for `Model.feature_columns` and `Model.label_columns` (googleapis#1117)

docs: Add migration guide from version 2.x to 3.x (googleapis#1027)

Release-As: 3.0.0
@derHeinzer derHeinzer mentioned this pull request Sep 8, 2022
Optional switch to non-nullable dtypes in to_dataframe #1345
Closed
@1oglop1 1oglop1 mentioned this pull request Sep 13, 2022
insert_rows_from_dataframe produces int64 is not JSON serializable #1348
Closed
abdelmegahedgoogle pushed a commit to abdelmegahedgoogle/python-bigquery that referenced this pull request Apr 17, 2023
@tswast @abdelmegahedgoogle
fix!: remove out-of-date BigQuery ML protocol buffers (googleapis#1178)
6ec1bf3
deps!: BigQuery Storage and pyarrow are required dependencies (googleapis#776)

fix!: use nullable `Int64` and `boolean` dtypes in `to_dataframe` (googleapis#786) 

feat!: destination tables are no-longer removed by `create_job` (googleapis#891)

feat!: In `to_dataframe`, use `dbdate` and `dbtime` dtypes from db-dtypes package for BigQuery DATE and TIME columns (googleapis#972)

fix!: automatically convert out-of-bounds dates in `to_dataframe`, remove `date_as_object` argument (googleapis#972)

feat!: mark the package as type-checked (googleapis#1058)

feat!: default to DATETIME type when loading timezone-naive datetimes from Pandas (googleapis#1061)

feat: add `api_method` parameter to `Client.query` to select `INSERT` or `QUERY` API (googleapis#967)

fix: improve type annotations for mypy validation (googleapis#1081)

feat: use `StandardSqlField` class for `Model.feature_columns` and `Model.label_columns` (googleapis#1117)

docs: Add migration guide from version 2.x to 3.x (googleapis#1027)

Release-As: 3.0.0
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

1 more reviewer
@plamut plamut plamut approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

api: bigquery Issues related to the googleapis/python-bigquery API. cla: yes This human has signed the Contributor License Agreement. semver: major Hint for users that this is an API breaking change.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

use pandas Int64 type by default to avoid precision loss

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@tswast @plamut
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.