|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
| 15 | +import datetime as dt |
15 | 16 | import itertools
|
16 | 17 | import logging
|
17 | 18 | import time
|
@@ -2271,6 +2272,68 @@ def test_to_dataframe(self):
|
2271 | 2272 | self.assertEqual(df.name.dtype.name, "object")
|
2272 | 2273 | self.assertEqual(df.age.dtype.name, "int64")
|
2273 | 2274 |
|
| 2275 | + @pytest.mark.xfail( |
| 2276 | + six.PY2, |
| 2277 | + reason=( |
| 2278 | + "Requires pyarrow>-1.0 to work, but the latter is not compatible " |
| 2279 | + "with Python 2 anymore." |
| 2280 | + ), |
| 2281 | + ) |
| 2282 | + @unittest.skipIf(pandas is None, "Requires `pandas`") |
| 2283 | + @unittest.skipIf(pyarrow is None, "Requires `pyarrow`") |
| 2284 | + def test_to_dataframe_timestamp_out_of_pyarrow_bounds(self): |
| 2285 | + from google.cloud.bigquery.schema import SchemaField |
| 2286 | + |
| 2287 | + schema = [SchemaField("some_timestamp", "TIMESTAMP")] |
| 2288 | + rows = [ |
| 2289 | + {"f": [{"v": "81953424000.0"}]}, # 4567-01-01 00:00:00 UTC |
| 2290 | + {"f": [{"v": "253402214400.0"}]}, # 9999-12-31 00:00:00 UTC |
| 2291 | + ] |
| 2292 | + path = "/foo" |
| 2293 | + api_request = mock.Mock(return_value={"rows": rows}) |
| 2294 | + row_iterator = self._make_one(_mock_client(), api_request, path, schema) |
| 2295 | + |
| 2296 | + df = row_iterator.to_dataframe(create_bqstorage_client=False) |
| 2297 | + |
| 2298 | + self.assertIsInstance(df, pandas.DataFrame) |
| 2299 | + self.assertEqual(len(df), 2) # verify the number of rows |
| 2300 | + self.assertEqual(list(df.columns), ["some_timestamp"]) |
| 2301 | + self.assertEqual( |
| 2302 | + list(df["some_timestamp"]), |
| 2303 | + [dt.datetime(4567, 1, 1), dt.datetime(9999, 12, 31)], |
| 2304 | + ) |
| 2305 | + |
| 2306 | + @pytest.mark.xfail( |
| 2307 | + six.PY2, |
| 2308 | + reason=( |
| 2309 | + "Requires pyarrow>-1.0 to work, but the latter is not compatible " |
| 2310 | + "with Python 2 anymore." |
| 2311 | + ), |
| 2312 | + ) |
| 2313 | + @unittest.skipIf(pandas is None, "Requires `pandas`") |
| 2314 | + @unittest.skipIf(pyarrow is None, "Requires `pyarrow`") |
| 2315 | + def test_to_dataframe_datetime_out_of_pyarrow_bounds(self): |
| 2316 | + from google.cloud.bigquery.schema import SchemaField |
| 2317 | + |
| 2318 | + schema = [SchemaField("some_datetime", "DATETIME")] |
| 2319 | + rows = [ |
| 2320 | + {"f": [{"v": "4567-01-01T00:00:00"}]}, |
| 2321 | + {"f": [{"v": "9999-12-31T00:00:00"}]}, |
| 2322 | + ] |
| 2323 | + path = "/foo" |
| 2324 | + api_request = mock.Mock(return_value={"rows": rows}) |
| 2325 | + row_iterator = self._make_one(_mock_client(), api_request, path, schema) |
| 2326 | + |
| 2327 | + df = row_iterator.to_dataframe(create_bqstorage_client=False) |
| 2328 | + |
| 2329 | + self.assertIsInstance(df, pandas.DataFrame) |
| 2330 | + self.assertEqual(len(df), 2) # verify the number of rows |
| 2331 | + self.assertEqual(list(df.columns), ["some_datetime"]) |
| 2332 | + self.assertEqual( |
| 2333 | + list(df["some_datetime"]), |
| 2334 | + [dt.datetime(4567, 1, 1), dt.datetime(9999, 12, 31)], |
| 2335 | + ) |
| 2336 | + |
2274 | 2337 | @unittest.skipIf(pandas is None, "Requires `pandas`")
|
2275 | 2338 | def test_to_dataframe_warning_wo_pyarrow(self):
|
2276 | 2339 | from google.cloud.bigquery.client import PyarrowMissingWarning
|
|
0 commit comments