|
27 | 27 | import warnings
|
28 | 28 |
|
29 | 29 | import mock
|
| 30 | +import packaging |
30 | 31 | import requests
|
31 | 32 | import pytest
|
32 | 33 | import pytz
|
@@ -7510,6 +7511,42 @@ def test_load_table_from_dataframe_wo_pyarrow_raises_error(self):
|
7510 | 7511 | parquet_compression="gzip",
|
7511 | 7512 | )
|
7512 | 7513 |
|
| 7514 | +def test_load_table_from_dataframe_w_bad_pyarrow_issues_warning(self): |
| 7515 | +pytest.importorskip("pandas", reason="Requires `pandas`") |
| 7516 | +pytest.importorskip("pyarrow", reason="Requires `pyarrow`") |
| 7517 | + |
| 7518 | +client = self._make_client() |
| 7519 | +records = [{"id": 1, "age": 100}, {"id": 2, "age": 60}] |
| 7520 | +dataframe = pandas.DataFrame(records) |
| 7521 | + |
| 7522 | +pyarrow_version_ = mock.( |
| 7523 | +"google.cloud.bigquery.client._PYARROW_VERSION", |
| 7524 | +packaging.version.parse("2.0.0"), # A known bad version of pyarrow. |
| 7525 | +) |
| 7526 | +get_table_ = mock.( |
| 7527 | +"google.cloud.bigquery.client.Client.get_table", |
| 7528 | +autospec=True, |
| 7529 | +side_effect=google.api_core.exceptions.NotFound("Table not found"), |
| 7530 | +) |
| 7531 | +load_ = mock.( |
| 7532 | +"google.cloud.bigquery.client.Client.load_table_from_file", autospec=True |
| 7533 | +) |
| 7534 | + |
| 7535 | +with load_, get_table_, pyarrow_version_: |
| 7536 | +with warnings.catch_warnings(record=True) as warned: |
| 7537 | +client.load_table_from_dataframe( |
| 7538 | +dataframe, self.TABLE_REF, location=self.LOCATION, |
| 7539 | +) |
| 7540 | + |
| 7541 | +expected_warnings = [ |
| 7542 | +warning for warning in warned if "pyarrow" in str(warning).lower() |
| 7543 | +] |
| 7544 | +assert len(expected_warnings) == 1 |
| 7545 | +assert issubclass(expected_warnings[0].category, RuntimeWarning) |
| 7546 | +msg = str(expected_warnings[0].message) |
| 7547 | +assert "pyarrow 2.0.0" in msg |
| 7548 | +assert "data corruption" in msg |
| 7549 | + |
7513 | 7550 | @unittest.skipIf(pandas is None, "Requires `pandas`")
|
7514 | 7551 | @unittest.skipIf(pyarrow is None, "Requires `pyarrow`")
|
7515 | 7552 | def test_load_table_from_dataframe_w_nulls(self):
|
|
0 commit comments