|
20 | 20 | import io |
21 | 21 | import json |
22 | 22 | import unittest |
| 23 | +import warnings |
23 | 24 |
|
24 | 25 | import mock |
25 | 26 | import requests |
@@ -4991,6 +4992,53 @@ def test_load_table_from_dataframe_w_custom_job_config(self): |
4991 | 4992 | assert sent_config is job_config |
4992 | 4993 | assert sent_config.source_format == job.SourceFormat.PARQUET |
4993 | 4994 |
|
| 4995 | + @unittest.skipIf(pandas is None, "Requires `pandas`") |
| 4996 | + @unittest.skipIf(pyarrow is None, "Requires `pyarrow`") |
| 4997 | + def test_load_table_from_dataframe_w_schema_wo_pyarrow(self): |
| 4998 | + from google.cloud.bigquery.client import _DEFAULT_NUM_RETRIES |
| 4999 | + from google.cloud.bigquery import job |
| 5000 | + from google.cloud.bigquery.schema import SchemaField |
| 5001 | + |
| 5002 | + client = self._make_client() |
| 5003 | + records = [{"name": "Monty", "age": 100}, {"name": "Python", "age": 60}] |
| 5004 | + dataframe = pandas.DataFrame(records) |
| 5005 | + schema = (SchemaField("name", "STRING"), SchemaField("age", "INTEGER")) |
| 5006 | + job_config = job.LoadJobConfig(schema=schema) |
| 5007 | + |
| 5008 | + load_patch = mock.patch( |
| 5009 | + "google.cloud.bigquery.client.Client.load_table_from_file", autospec=True |
| 5010 | + ) |
| 5011 | + pyarrow_patch = mock.patch("google.cloud.bigquery.client.pyarrow", None) |
| 5012 | + |
| 5013 | + with load_patch as load_table_from_file, pyarrow_patch, warnings.catch_warnings( |
| 5014 | + record=True |
| 5015 | + ) as warned: |
| 5016 | + client.load_table_from_dataframe( |
| 5017 | + dataframe, self.TABLE_REF, job_config=job_config, location=self.LOCATION |
| 5018 | + ) |
| 5019 | + |
| 5020 | + assert len(warned) == 1 |
| 5021 | + warning = warned[0] |
| 5022 | + assert warning.category is PendingDeprecationWarning |
| 5023 | + assert "pyarrow" in str(warning) |
| 5024 | + |
| 5025 | + load_table_from_file.assert_called_once_with( |
| 5026 | + client, |
| 5027 | + mock.ANY, |
| 5028 | + self.TABLE_REF, |
| 5029 | + num_retries=_DEFAULT_NUM_RETRIES, |
| 5030 | + rewind=True, |
| 5031 | + job_id=mock.ANY, |
| 5032 | + job_id_prefix=None, |
| 5033 | + location=self.LOCATION, |
| 5034 | + project=None, |
| 5035 | + job_config=mock.ANY, |
| 5036 | + ) |
| 5037 | + |
| 5038 | + sent_config = load_table_from_file.mock_calls[0][2]["job_config"] |
| 5039 | + assert sent_config.source_format == job.SourceFormat.PARQUET |
| 5040 | + assert tuple(sent_config.schema) == schema |
| 5041 | + |
4994 | 5042 | @unittest.skipIf(pandas is None, "Requires `pandas`") |
4995 | 5043 | @unittest.skipIf(pyarrow is None, "Requires `pyarrow`") |
4996 | 5044 | def test_load_table_from_dataframe_w_nulls(self): |
|
0 commit comments