Skip to content

fix: read_gbq supports extreme DATETIME values such as 0001-01-01 00:00:00 #444

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

Merged
merged 40 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
933d470
fix: read out-of-bounds DATETIME values such as `0001-01-01 00:00:00`
tswast Dec 6, 2021
9a9d3fd
feat: accepts a table ID, which downloads the table without a query
tswast Dec 6, 2021
2a76982
revert tests for read_gbq fix which isn't yet resolved
tswast Dec 6, 2021
4695c5f
Revert "revert tests for read_gbq fix which isn't yet resolved"
tswast Dec 6, 2021
6adf233
add todo for next steps
tswast Dec 6, 2021
73a791a
Merge remote-tracking branch 'upstream/main' into issue266-read_gbq-n…
tswast Dec 9, 2021
9b1eb0d
add unit test for table ID read_gbq
tswast Dec 9, 2021
ec9ddaf
add helper for is_query
tswast Dec 9, 2021
9cc7c74
implement read_gbq with table id
tswast Dec 10, 2021
dd51ad8
fix remaining tests, don't localalize out-of-bounds timestamp columns
tswast Dec 10, 2021
e1ad679
Update pandas_gbq/gbq.py
tswast Dec 10, 2021
d29bc2a
fix 3.7 unit tests
tswast Dec 10, 2021
cb8f24f
correct coverage
tswast Dec 10, 2021
56b73b2
skip coverage for optional test skip
tswast Dec 10, 2021
8a61e97
fix docs build
tswast Dec 10, 2021
3f7900b
improve test coverage for error case
tswast Dec 10, 2021
ae3e044
Merge branch 'issue266-read_gbq-no-query' into issue365-extreme-datet…
tswast Dec 10, 2021
3c53f1f
as of google-cloud-bigquery 1.11.0, get_table before list_rows is unn…
tswast Dec 13, 2021
c98982d
Merge branch 'issue266-read_gbq-no-query' into issue365-extreme-datet…
tswast Dec 13, 2021
f0acde6
refactor tests
tswast Dec 13, 2021
362a26d
add more scalars
tswast Dec 14, 2021
752d67c
add more types
tswast Dec 14, 2021
5b46127
add failing time test
tswast Dec 15, 2021
254f6a0
add test for bignumeric
tswast Dec 15, 2021
c0780b6
add test for null values
tswast Dec 15, 2021
9aaedc6
add epoch timestamps to tests
tswast Dec 15, 2021
b03443b
add post-download dtype conversions
tswast Dec 16, 2021
cd6ae70
Merge remote-tracking branch 'upstream/main' into issue365-extreme-da…
tswast Dec 29, 2021
11126a6
add failing test for desired fix
tswast Dec 29, 2021
14e6070
fix the issue with extreme datetimes
tswast Dec 29, 2021
8f92d9b
fix constraints
tswast Dec 29, 2021
9985d15
fix tests for empty dataframe
tswast Dec 30, 2021
6fb73a2
fix tests for older google-cloud-bigquery
tswast Dec 30, 2021
8cc4524
ignore index on empty dataframe
tswast Dec 30, 2021
a0d6cad
add db-dtypes to runtime import checks
tswast Dec 30, 2021
dfa6942
Merge remote-tracking branch 'upstream/main' into issue365-extreme-da…
tswast Jan 4, 2022
82c5362
document dependencies
tswast Jan 4, 2022
de4a06e
remove TODO, since done
tswast Jan 4, 2022
9fc8c08
remove unnecessary special case for empty dataframe
tswast Jan 4, 2022
c5c0e85
remove redundant 'deprecated' from comment
tswast Jan 5, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ci/requirements-3.7-0.24.2.conda
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
codecov
coverage
db-dtypes==0.3.0
db-dtypes==0.3.1
fastavro
flake8
numpy==1.16.6
google-cloud-bigquery==1.11.1
google-cloud-bigquery==1.26.1
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Needed for date_as_object parameter

google-cloud-bigquery-storage==1.1.0
pyarrow==3.0.0
pydata-google-auth
pytest
Expand Down
9 changes: 7 additions & 2 deletions pandas_gbq/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,13 @@ def cast_dataframe_for_parquet(
# .astype() with DateDtype. With .astype(), I get the error:
#
# TypeError: Cannot interpret '<db_dtypes.DateDtype ...>' as a data type
cast_column = pandas.Series(
dataframe[column_name], dtype=db_dtypes.DateDtype()
cast_column = dataframe[column_name].astype(
dtype=db_dtypes.DateDtype(),
# Return the original column if there was an error converting
# to the dtype, such as is there is a date outside the
# supported range.
# https://github.com/googleapis/python-bigquery-pandas/issues/441
errors="ignore",
)
elif column_type in {"NUMERIC", "DECIMAL", "BIGNUMERIC", "BIGDECIMAL"}:
cast_column = dataframe[column_name].map(decimal.Decimal)
Expand Down
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@
release_status = "Development Status :: 4 - Beta"
dependencies = [
"setuptools",
"db-dtypes >=0.3.0,<2.0.0",
"numpy>=1.16.6",
"pandas>=0.24.2",
"db-dtypes >=0.3.1,<2.0.0",
"numpy >=1.16.6",
"pandas >=0.24.2",
"pyarrow >=3.0.0, <7.0dev",
"pydata-google-auth",
"google-auth",
"google-auth-oauthlib",
# 2.4.* has a bug where waiting for the query can hang indefinitely.
# https://github.com/pydata/pandas-gbq/issues/343
"google-cloud-bigquery[bqstorage,pandas]>=1.11.1,<3.0.0dev,!=2.4.*",
"google-cloud-bigquery >=1.26.1,<3.0.0dev,!=2.4.*",
"google-cloud-bigquery-storage >=1.1.0,<3.0.0dev",
]
extras = {
"tqdm": "tqdm>=4.23.0",
Expand Down
6 changes: 3 additions & 3 deletions testing/constraints-3.7.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#
# e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev",
# Then this file should have foo==1.14.0
db-dtypes==0.3.0
google-auth==1.4.1
db-dtypes==0.3.1
google-auth==1.18.0
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't match the minimum constraint in setup.py.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated setup.py. Needed this version due to updated google-api-core (via google-cloud-bigquery)

google-auth-oauthlib==0.0.1
google-cloud-bigquery==1.11.1
google-cloud-bigquery==1.26.1
google-cloud-bigquery-storage==1.1.0
numpy==1.16.6
pandas==0.24.2
Expand Down
48 changes: 48 additions & 0 deletions tests/system/test_to_gbq.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,54 @@ def test_series_round_trip(
{"name": "num_col", "type": "NUMERIC"},
],
),
pytest.param(
*DataFrameRoundTripTestCase(
input_df=pandas.DataFrame(
{
"row_num": [1, 2, 3],
# DATE valuess outside the pandas range for timestamp
# aren't supported by the db-dtypes package.
# https://github.com/googleapis/python-bigquery-pandas/issues/441
"date_col": [
datetime.date(1, 1, 1),
datetime.date(1970, 1, 1),
datetime.date(9999, 12, 31),
],
# DATETIME values outside of the range for pandas timestamp
# require `date_as_object` parameter in
# google-cloud-bigquery versions 1.x and 2.x.
# https://github.com/googleapis/python-bigquery-pandas/issues/365
"datetime_col": [
datetime.datetime(1, 1, 1),
datetime.datetime(1970, 1, 1),
datetime.datetime(9999, 12, 31, 23, 59, 59, 999999),
],
"timestamp_col": [
datetime.datetime(1, 1, 1, tzinfo=datetime.timezone.utc),
datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc),
datetime.datetime(
9999,
12,
31,
23,
59,
59,
999999,
tzinfo=datetime.timezone.utc,
),
],
},
columns=["row_num", "date_col", "datetime_col", "timestamp_col"],
),
table_schema=[
{"name": "row_num", "type": "INTEGER"},
{"name": "date_col", "type": "DATE"},
{"name": "datetime_col", "type": "DATETIME"},
{"name": "timestamp_col", "type": "TIMESTAMP"},
],
),
id="issue365-extreme-datetimes",
),
]


Expand Down