From 12345bb46f5a739dfc79d7d43e7bc0ffed35683b Mon Sep 17 00:00:00 2001 From: HemangChothani Date: Tue, 18 Feb 2020 12:27:50 +0530 Subject: [PATCH] feat(bigquery): refactor code --- tests/system.py | 37 +++++++++++++++++++------------------ tests/unit/test_client.py | 4 ++-- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/tests/system.py b/tests/system.py index 700f6e6184..9ea59b192a 100644 --- a/tests/system.py +++ b/tests/system.py @@ -738,61 +738,62 @@ def test_load_table_from_dataframe_w_automatic_schema(self): @unittest.skipIf( pandas is None or pandas.__version__ < "1.0.1", - "Only `pandas version >=1.0.1` supports", + "Only `pandas version >=1.0.1` is supported", ) @unittest.skipIf(pyarrow is None, "Requires `pyarrow`") def test_load_table_from_dataframe_w_none_value(self): - """Test that a DataFrame with dtypes that map well to BigQuery types - can be uploaded without specifying a schema. + """Test that a DataFrame containing None-type values can be uploaded + if a BigQuery schema is specified. https://github.com/googleapis/python-bigquery/issues/22 """ - df_data = collections.OrderedDict( - [("x", pandas.Series([1, 2, None, 4], dtype="Int64"))] - ) - dataframe = pandas.DataFrame(df_data, columns=df_data.keys()) - table_schema = (bigquery.SchemaField("x", "INTEGER", mode="NULLABLE"),) + dataset_id = _make_dataset_id("bq_load_test") self.temp_dataset(dataset_id) table_id = "{}.{}.load_table_from_dataframe_w_none_value".format( Config.CLIENT.project, dataset_id ) + table_schema = (bigquery.SchemaField("x", "INTEGER", mode="NULLABLE"),) table = retry_403(Config.CLIENT.create_table)( Table(table_id, schema=table_schema) ) self.to_delete.insert(0, table) + df_data = collections.OrderedDict( + [("x", pandas.Series([1, 2, None, 4], dtype="Int64"))] + ) + dataframe = pandas.DataFrame(df_data, columns=df_data.keys()) load_job = Config.CLIENT.load_table_from_dataframe(dataframe, table_id) load_job.result() table = Config.CLIENT.get_table(table_id) - self.assertEqual(tuple(table.schema), ((bigquery.SchemaField("x", "INTEGER"),))) + self.assertEqual(tuple(table.schema), (bigquery.SchemaField("x", "INTEGER"),)) self.assertEqual(table.num_rows, 4) @unittest.skipIf( pandas is None or pandas.__version__ < "1.0.1", - "Only `pandas version >=1.0.1` supports", + "Only `pandas version >=1.0.1` is supported", ) @unittest.skipIf(pyarrow is None, "Requires `pyarrow`") def test_load_table_from_dataframe_w_automatic_schema_w_none_value(self): - """Test that a DataFrame with dtypes that map well to BigQuery types - can be uploaded without specifying a schema. + """Test that a DataFrame containing None-type values can be uploaded + without specifying a schema. https://github.com/googleapis/python-bigquery/issues/22 """ - df_data = collections.OrderedDict( - [("x", pandas.Series([1, 2, None, 4], dtype="Int64"))] - ) - dataframe = pandas.DataFrame(df_data, columns=df_data.keys()) + dataset_id = _make_dataset_id("bq_load_test") self.temp_dataset(dataset_id) table_id = "{}.{}.load_table_from_dataframe_w_automatic_schema_w_none_value".format( Config.CLIENT.project, dataset_id ) - + df_data = collections.OrderedDict( + [("x", pandas.Series([1, 2, None, 4], dtype="Int64"))] + ) + dataframe = pandas.DataFrame(df_data, columns=df_data.keys()) load_job = Config.CLIENT.load_table_from_dataframe(dataframe, table_id) load_job.result() table = Config.CLIENT.get_table(table_id) - self.assertEqual(tuple(table.schema), ((bigquery.SchemaField("x", "INTEGER"),))) + self.assertEqual(tuple(table.schema), (bigquery.SchemaField("x", "INTEGER"),)) self.assertEqual(table.num_rows, 4) @unittest.skipIf(pandas is None, "Requires `pandas`") diff --git a/tests/unit/test_client.py b/tests/unit/test_client.py index ec3cb0cc5a..f758311016 100644 --- a/tests/unit/test_client.py +++ b/tests/unit/test_client.py @@ -6633,7 +6633,7 @@ def test_load_table_from_dataframe_no_schema_warning_wo_pyarrow(self): @unittest.skipIf( pandas is None or pandas.__version__ < "1.0.1", - "Only `pandas version >=1.0.1` supports", + "Only `pandas version >=1.0.1` is supported", ) @unittest.skipIf(pyarrow is None, "Requires `pyarrow`") def test_load_table_from_dataframe_w_none_value(self): @@ -6679,7 +6679,7 @@ def test_load_table_from_dataframe_w_none_value(self): @unittest.skipIf( pandas is None or pandas.__version__ < "1.0.1", - "Only `pandas version >=1.0.1` supports", + "Only `pandas version >=1.0.1` is supported", ) @unittest.skipIf(pyarrow is None, "Requires `pyarrow`") def test_load_table_from_dataframe_w_automatic_schema_w_none_value(self):