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: remove pytz dependency and require pyarrow>=3.0.0 #875

Merged
merged 7 commits into from Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/snippets.py
Expand Up @@ -363,7 +363,6 @@ def test_update_table_expiration(client, to_delete):

# [START bigquery_update_table_expiration]
import datetime
import pytz

# from google.cloud import bigquery
# client = bigquery.Client()
Expand All @@ -375,7 +374,9 @@ def test_update_table_expiration(client, to_delete):
assert table.expires is None

# set table to expire 5 days from now
expiration = datetime.datetime.now(pytz.utc) + datetime.timedelta(days=5)
expiration = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(
days=5
)
table.expires = expiration
table = client.update_table(table, ["expires"]) # API request

Expand Down
3 changes: 1 addition & 2 deletions google/cloud/bigquery/table.py
Expand Up @@ -20,7 +20,6 @@
import datetime
import functools
import operator
import pytz
import typing
from typing import Any, Dict, Iterable, Iterator, Optional, Tuple
import warnings
Expand Down Expand Up @@ -1969,7 +1968,7 @@ def to_dataframe(
# Pandas, we set the timestamp_as_object parameter to True, if necessary.
types_to_check = {
pyarrow.timestamp("us"),
pyarrow.timestamp("us", tz=pytz.UTC),
pyarrow.timestamp("us", tz=datetime.timezone.utc),
}

for column in record_batch:
Expand Down
3 changes: 1 addition & 2 deletions samples/client_query_w_timestamp_params.py
Expand Up @@ -18,7 +18,6 @@ def client_query_w_timestamp_params():
# [START bigquery_query_params_timestamps]
import datetime

import pytz
from google.cloud import bigquery

# Construct a BigQuery client object.
Expand All @@ -30,7 +29,7 @@ def client_query_w_timestamp_params():
bigquery.ScalarQueryParameter(
"ts_value",
"TIMESTAMP",
datetime.datetime(2016, 12, 7, 8, 0, tzinfo=pytz.UTC),
datetime.datetime(2016, 12, 7, 8, 0, tzinfo=datetime.timezone.utc),
)
]
)
Expand Down
13 changes: 7 additions & 6 deletions tests/system/test_pandas.py
Expand Up @@ -24,7 +24,6 @@
import google.api_core.retry
import pkg_resources
import pytest
import pytz

from google.cloud import bigquery
from google.cloud.bigquery._pandas_helpers import _BIGNUMERIC_SUPPORT
Expand Down Expand Up @@ -64,7 +63,7 @@ def test_load_table_from_dataframe_w_automatic_schema(bigquery_client, dataset_i
datetime.datetime(2012, 3, 14, 15, 16),
],
dtype="datetime64[ns]",
).dt.tz_localize(pytz.utc),
).dt.tz_localize(datetime.timezone.utc),
),
(
"dt_col",
Expand Down Expand Up @@ -348,9 +347,11 @@ def test_load_table_from_dataframe_w_explicit_schema(bigquery_client, dataset_id
(
"ts_col",
[
datetime.datetime(1, 1, 1, 0, 0, 0, tzinfo=pytz.utc),
datetime.datetime(1, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc),
None,
datetime.datetime(9999, 12, 31, 23, 59, 59, 999999, tzinfo=pytz.utc),
datetime.datetime(
9999, 12, 31, 23, 59, 59, 999999, tzinfo=datetime.timezone.utc
),
],
),
]
Expand Down Expand Up @@ -484,10 +485,10 @@ def test_load_table_from_dataframe_w_explicit_schema_source_format_csv(
(
"ts_col",
[
datetime.datetime(1, 1, 1, 0, 0, 0, tzinfo=pytz.utc),
datetime.datetime(1, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc),
None,
datetime.datetime(
9999, 12, 31, 23, 59, 59, 999999, tzinfo=pytz.utc
9999, 12, 31, 23, 59, 59, 999999, tzinfo=datetime.timezone.utc
),
],
),
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/job/test_base.py
Expand Up @@ -295,11 +295,11 @@ def test_user_email(self):
@staticmethod
def _datetime_and_millis():
import datetime
import pytz
from google.cloud._helpers import _millis

now = datetime.datetime.utcnow().replace(
microsecond=123000, tzinfo=pytz.UTC # stats timestamps have ms precision
microsecond=123000,
tzinfo=datetime.timezone.utc, # stats timestamps have ms precision
)
return now, _millis(now)

Expand Down
13 changes: 7 additions & 6 deletions tests/unit/test__pandas_helpers.py
Expand Up @@ -37,7 +37,6 @@
# used in test parameterization.
pyarrow = mock.Mock()
import pytest
import pytz

from google import api_core
from google.cloud.bigquery import _helpers
Expand Down Expand Up @@ -456,10 +455,12 @@ def test_bq_to_arrow_data_type_w_struct_unknown_subfield(module_under_test):
(
"TIMESTAMP",
[
datetime.datetime(1, 1, 1, 0, 0, 0, tzinfo=pytz.utc),
datetime.datetime(1, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc),
None,
datetime.datetime(9999, 12, 31, 23, 59, 59, 999999, tzinfo=pytz.utc),
datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=pytz.utc),
datetime.datetime(
9999, 12, 31, 23, 59, 59, 999999, tzinfo=datetime.timezone.utc
),
datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc),
],
),
(
Expand Down Expand Up @@ -960,8 +961,8 @@ def test_dataframe_to_arrow_with_required_fields(module_under_test):
"field09": [True, False],
"field10": [False, True],
"field11": [
datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=pytz.utc),
datetime.datetime(2012, 12, 21, 9, 7, 42, tzinfo=pytz.utc),
datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc),
datetime.datetime(2012, 12, 21, 9, 7, 42, tzinfo=datetime.timezone.utc),
],
"field12": [datetime.date(9999, 12, 31), datetime.date(1970, 1, 1)],
"field13": [datetime.time(23, 59, 59, 999999), datetime.time(12, 0, 0)],
Expand Down
21 changes: 14 additions & 7 deletions tests/unit/test_client.py
Expand Up @@ -30,7 +30,6 @@
import packaging
import requests
import pytest
import pytz
import pkg_resources

try:
Expand Down Expand Up @@ -5018,16 +5017,24 @@ def test_insert_rows_w_repeated_fields(self):
(
12,
[
datetime.datetime(2018, 12, 1, 12, 0, 0, tzinfo=pytz.utc),
datetime.datetime(2018, 12, 1, 13, 0, 0, tzinfo=pytz.utc),
datetime.datetime(
2018, 12, 1, 12, 0, 0, tzinfo=datetime.timezone.utc
),
datetime.datetime(
2018, 12, 1, 13, 0, 0, tzinfo=datetime.timezone.utc
),
],
[1.25, 2.5],
),
{
"score": 13,
"times": [
datetime.datetime(2018, 12, 2, 12, 0, 0, tzinfo=pytz.utc),
datetime.datetime(2018, 12, 2, 13, 0, 0, tzinfo=pytz.utc),
datetime.datetime(
2018, 12, 2, 12, 0, 0, tzinfo=datetime.timezone.utc
),
datetime.datetime(
2018, 12, 2, 13, 0, 0, tzinfo=datetime.timezone.utc
),
],
"distances": [-1.25, -2.5],
},
Expand Down Expand Up @@ -6974,7 +6981,7 @@ def test_load_table_from_dataframe_w_automatic_schema(self):
datetime.datetime(2012, 3, 14, 15, 16),
],
dtype="datetime64[ns]",
).dt.tz_localize(pytz.utc),
).dt.tz_localize(datetime.timezone.utc),
),
]
)
Expand Down Expand Up @@ -7306,7 +7313,7 @@ def test_load_table_from_dataframe_w_partial_schema(self):
datetime.datetime(2012, 3, 14, 15, 16),
],
dtype="datetime64[ns]",
).dt.tz_localize(pytz.utc),
).dt.tz_localize(datetime.timezone.utc),
),
("string_col", ["abc", None, "def"]),
("bytes_col", [b"abc", b"def", None]),
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_table.py
Expand Up @@ -22,7 +22,6 @@
import mock
import pkg_resources
import pytest
import pytz

import google.api_core.exceptions
from test_utils.imports import maybe_fail_import
Expand Down Expand Up @@ -914,7 +913,9 @@ def test_mview_last_refresh_time(self):
}
self.assertEqual(
table.mview_last_refresh_time,
datetime.datetime(2020, 11, 30, 15, 57, 22, 496000, tzinfo=pytz.utc),
datetime.datetime(
2020, 11, 30, 15, 57, 22, 496000, tzinfo=datetime.timezone.utc
),
)

def test_mview_enable_refresh(self):
Expand Down