Skip to content

Commit 5f7e35a

Browse files
committed
test on various pandas versions
1 parent 46dd0c8 commit 5f7e35a

File tree

4 files changed

+48
-13
lines changed

4 files changed

+48
-13
lines changed

testing/constraints-3.10.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
numpy==1.26.4
2+
pandas==2.0.3

testing/constraints-3.11.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pandas==2.1.4

testing/constraints-3.9.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
numpy==1.19.4
2-
pandas==1.1.4
1+
numpy==1.20.3
2+
pandas==1.5.3

tests/unit/test_gbq.py

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
pytestmark = pytest.mark.filterwarnings("ignore:credentials from Google Cloud SDK")
2929

3030

31+
PANDAS_VERSION = tuple(int(part) for part in pandas.__version__.split(".")[:2])
32+
33+
3134
def _make_connector(project_id="some-project", **kwargs):
3235
return gbq.GbqConnector(project_id, **kwargs)
3336

@@ -113,34 +116,63 @@ def test__bqschema_to_nullsafe_dtypes(type_, expected):
113116
assert result == {"x": expected}
114117

115118

116-
@pytest.mark.skipif(
117-
tuple(int(part) for part in pandas.__version__.split(".")[:2]) < (2, 1),
118-
reason="requires pandas 2.1.0 or higher"
119-
)
120119
@pytest.mark.parametrize(
121120
("data", "schema_type", "expected"),
122121
[
123-
(
122+
pytest.param(
124123
pandas.to_datetime(["2017-01-01T12:00:00Z"]).astype(
125-
pandas.DatetimeTZDtype(unit="us", tz="UTC")
124+
pandas.DatetimeTZDtype(
125+
# Microseconds aren't supported until newer pandas.
126+
# https://github.com/googleapis/python-bigquery-pandas/issues/852
127+
unit="us" if PANDAS_VERSION >= (2, 1) else "ns",
128+
tz="UTC",
129+
),
126130
),
127131
"TIMESTAMP",
128-
pandas.DatetimeTZDtype(unit="us", tz="UTC"),
132+
pandas.DatetimeTZDtype(
133+
# Microseconds aren't supported until newer pandas.
134+
# https://github.com/googleapis/python-bigquery-pandas/issues/852
135+
unit="us" if PANDAS_VERSION >= (2, 1) else "ns",
136+
tz="UTC",
137+
),
129138
),
130139
(
131140
pandas.to_datetime([]).astype(object),
132141
"TIMESTAMP",
133-
pandas.DatetimeTZDtype(unit="us", tz="UTC"),
142+
pandas.DatetimeTZDtype(
143+
# Microseconds aren't supported until newer pandas.
144+
# https://github.com/googleapis/python-bigquery-pandas/issues/852
145+
unit="us" if PANDAS_VERSION >= (2, 1) else "ns",
146+
tz="UTC",
147+
),
134148
),
135149
(
136-
pandas.to_datetime(["2017-01-01T12:00:00"]).astype("datetime64[us]"),
150+
pandas.to_datetime(["2017-01-01T12:00:00"]).astype(
151+
# Microseconds aren't supported until newer pandas.
152+
# https://github.com/googleapis/python-bigquery-pandas/issues/852
153+
"datetime64[us]"
154+
if PANDAS_VERSION >= (2, 1)
155+
else "datetime64[ns]",
156+
),
137157
"DATETIME",
138-
numpy.dtype("datetime64[us]"),
158+
numpy.dtype(
159+
# Microseconds aren't supported until newer pandas.
160+
# https://github.com/googleapis/python-bigquery-pandas/issues/852
161+
"datetime64[us]"
162+
if PANDAS_VERSION >= (2, 1)
163+
else "datetime64[ns]",
164+
),
139165
),
140166
(
141167
pandas.to_datetime([]).astype(object),
142168
"DATETIME",
143-
numpy.dtype("datetime64[us]"),
169+
numpy.dtype(
170+
# Microseconds aren't supported until newer pandas.
171+
# https://github.com/googleapis/python-bigquery-pandas/issues/852
172+
"datetime64[us]"
173+
if PANDAS_VERSION >= (2, 1)
174+
else "datetime64[ns]",
175+
),
144176
),
145177
],
146178
)

0 commit comments

Comments
 (0)