|
28 | 28 | pytestmark = pytest.mark.filterwarnings("ignore:credentials from Google Cloud SDK")
|
29 | 29 |
|
30 | 30 |
|
| 31 | +PANDAS_VERSION = tuple(int(part) for part in pandas.__version__.split(".")[:2]) |
| 32 | + |
| 33 | + |
31 | 34 | def _make_connector(project_id="some-project", **kwargs):
|
32 | 35 | return gbq.GbqConnector(project_id, **kwargs)
|
33 | 36 |
|
@@ -113,34 +116,63 @@ def test__bqschema_to_nullsafe_dtypes(type_, expected):
|
113 | 116 | assert result == {"x": expected}
|
114 | 117 |
|
115 | 118 |
|
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 |
| -) |
120 | 119 | @pytest.mark.parametrize(
|
121 | 120 | ("data", "schema_type", "expected"),
|
122 | 121 | [
|
123 |
| - ( |
| 122 | + pytest.param( |
124 | 123 | 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 | + ), |
126 | 130 | ),
|
127 | 131 | "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 | + ), |
129 | 138 | ),
|
130 | 139 | (
|
131 | 140 | pandas.to_datetime([]).astype(object),
|
132 | 141 | "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 | + ), |
134 | 148 | ),
|
135 | 149 | (
|
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 | + ), |
137 | 157 | "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 | + ), |
139 | 165 | ),
|
140 | 166 | (
|
141 | 167 | pandas.to_datetime([]).astype(object),
|
142 | 168 | "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 | + ), |
144 | 176 | ),
|
145 | 177 | ],
|
146 | 178 | )
|
|
0 commit comments