From 829ba9c999d6f4d511dec38c834bfa8bc8e85b04 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sat, 10 Jun 2017 22:35:55 -0400 Subject: [PATCH 1/3] TST: Fix broken tests failing with 'NoneType' object is not iterable --- pandas_gbq/gbq.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas_gbq/gbq.py b/pandas_gbq/gbq.py index e584bd8f..8d389100 100644 --- a/pandas_gbq/gbq.py +++ b/pandas_gbq/gbq.py @@ -1055,6 +1055,9 @@ def datasets(self): dataset_response = list_dataset_response.get('datasets') next_page_token = list_dataset_response.get('nextPageToken') + if dataset_response is None: + dataset_response = [] + for row_num, raw_row in enumerate(dataset_response): dataset_list.append( raw_row['datasetReference']['datasetId']) From cbcfe16be5530a46fcd51237e7e63e35d00f4d60 Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Fri, 19 May 2017 12:44:14 -0700 Subject: [PATCH 2/3] MAINT: pandas.util.testing.assertRaises removed This method was removed in https://github.com/pandas-dev/pandas/pull/16089 in favor of pytest.raises. --- pandas_gbq/tests/test_gbq.py | 51 ++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/pandas_gbq/tests/test_gbq.py b/pandas_gbq/tests/test_gbq.py index 9386f17b..07c4e68a 100644 --- a/pandas_gbq/tests/test_gbq.py +++ b/pandas_gbq/tests/test_gbq.py @@ -9,6 +9,7 @@ import logging import numpy as np +import pytest from distutils.version import StrictVersion from pandas import compat @@ -375,7 +376,7 @@ def test_import_google_api_python_client(self): "using google-api-python-client==1.2") if compat.PY2: - with tm.assertRaises(ImportError): + with pytest.raises(ImportError): from googleapiclient.discovery import build # noqa from googleapiclient.errors import HttpError # noqa from apiclient.discovery import build # noqa @@ -405,15 +406,15 @@ def test_should_return_bigquery_strings_as_python_strings(self): tm.assert_equal(result, 'STRING') def test_to_gbq_should_fail_if_invalid_table_name_passed(self): - with tm.assertRaises(gbq.NotFoundException): + with pytest.raises(gbq.NotFoundException): gbq.to_gbq(DataFrame(), 'invalid_table_name', project_id="1234") def test_to_gbq_with_no_project_id_given_should_fail(self): - with tm.assertRaises(TypeError): + with pytest.raises(TypeError): gbq.to_gbq(DataFrame(), 'dataset.tablename') def test_read_gbq_with_no_project_id_given_should_fail(self): - with tm.assertRaises(TypeError): + with pytest.raises(TypeError): gbq.read_gbq('SELECT 1') def test_that_parse_data_works_properly(self): @@ -426,29 +427,29 @@ def test_that_parse_data_works_properly(self): tm.assert_frame_equal(test_output, correct_output) def test_read_gbq_with_invalid_private_key_json_should_fail(self): - with tm.assertRaises(gbq.InvalidPrivateKeyFormat): + with pytest.raises(gbq.InvalidPrivateKeyFormat): gbq.read_gbq('SELECT 1', project_id='x', private_key='y') def test_read_gbq_with_empty_private_key_json_should_fail(self): - with tm.assertRaises(gbq.InvalidPrivateKeyFormat): + with pytest.raises(gbq.InvalidPrivateKeyFormat): gbq.read_gbq('SELECT 1', project_id='x', private_key='{}') def test_read_gbq_with_private_key_json_wrong_types_should_fail(self): - with tm.assertRaises(gbq.InvalidPrivateKeyFormat): + with pytest.raises(gbq.InvalidPrivateKeyFormat): gbq.read_gbq( 'SELECT 1', project_id='x', private_key='{ "client_email" : 1, "private_key" : True }') def test_read_gbq_with_empty_private_key_file_should_fail(self): with tm.ensure_clean() as empty_file_path: - with tm.assertRaises(gbq.InvalidPrivateKeyFormat): + with pytest.raises(gbq.InvalidPrivateKeyFormat): gbq.read_gbq('SELECT 1', project_id='x', private_key=empty_file_path) def test_read_gbq_with_corrupted_private_key_json_should_fail(self): _skip_if_no_private_key_contents() - with tm.assertRaises(gbq.InvalidPrivateKeyFormat): + with pytest.raises(gbq.InvalidPrivateKeyFormat): gbq.read_gbq( 'SELECT 1', project_id='x', private_key=re.sub('[a-z]', '9', _get_private_key_contents())) @@ -725,7 +726,7 @@ def test_read_gbq_raises_invalid_column_order(self): col_order = ['string_aaa', 'string_1', 'string_2'] # Column string_aaa does not exist. Should raise InvalidColumnOrder - with tm.assertRaises(gbq.InvalidColumnOrder): + with pytest.raises(gbq.InvalidColumnOrder): gbq.read_gbq(query, project_id=_get_project_id(), col_order=col_order, private_key=_get_private_key_path()) @@ -747,24 +748,24 @@ def test_read_gbq_raises_invalid_index_column(self): col_order = ['string_3', 'string_2'] # Column string_bbb does not exist. Should raise InvalidIndexColumn - with tm.assertRaises(gbq.InvalidIndexColumn): + with pytest.raises(gbq.InvalidIndexColumn): gbq.read_gbq(query, project_id=_get_project_id(), index_col='string_bbb', col_order=col_order, private_key=_get_private_key_path()) def test_malformed_query(self): - with tm.assertRaises(gbq.GenericGBQException): + with pytest.raises(gbq.GenericGBQException): gbq.read_gbq("SELCET * FORM [publicdata:samples.shakespeare]", project_id=_get_project_id(), private_key=_get_private_key_path()) def test_bad_project_id(self): - with tm.assertRaises(gbq.GenericGBQException): + with pytest.raises(gbq.GenericGBQException): gbq.read_gbq("SELECT 1", project_id='001', private_key=_get_private_key_path()) def test_bad_table_name(self): - with tm.assertRaises(gbq.GenericGBQException): + with pytest.raises(gbq.GenericGBQException): gbq.read_gbq("SELECT * FROM [publicdata:samples.nope]", project_id=_get_project_id(), private_key=_get_private_key_path()) @@ -800,7 +801,7 @@ def test_legacy_sql(self): # Test that a legacy sql statement fails when # setting dialect='standard' - with tm.assertRaises(gbq.GenericGBQException): + with pytest.raises(gbq.GenericGBQException): gbq.read_gbq(legacy_sql, project_id=_get_project_id(), dialect='standard', private_key=_get_private_key_path()) @@ -818,7 +819,7 @@ def test_standard_sql(self): # Test that a standard sql statement fails when using # the legacy SQL dialect (default value) - with tm.assertRaises(gbq.GenericGBQException): + with pytest.raises(gbq.GenericGBQException): gbq.read_gbq(standard_sql, project_id=_get_project_id(), private_key=_get_private_key_path()) @@ -834,7 +835,7 @@ def test_invalid_option_for_sql_dialect(self): "`publicdata.samples.wikipedia` LIMIT 10" # Test that an invalid option for `dialect` raises ValueError - with tm.assertRaises(ValueError): + with pytest.raises(ValueError): gbq.read_gbq(sql_statement, project_id=_get_project_id(), dialect='invalid', private_key=_get_private_key_path()) @@ -874,7 +875,7 @@ def test_query_with_parameters(self): } # Test that a query that relies on parameters fails # when parameters are not supplied via configuration - with tm.assertRaises(ValueError): + with pytest.raises(ValueError): gbq.read_gbq(sql_statement, project_id=_get_project_id(), private_key=_get_private_key_path()) @@ -896,7 +897,7 @@ def test_query_inside_configuration(self): } # Test that it can't pass query both # inside config and as parameter - with tm.assertRaises(ValueError): + with pytest.raises(ValueError): gbq.read_gbq(query_no_use, project_id=_get_project_id(), private_key=_get_private_key_path(), configuration=config) @@ -924,7 +925,7 @@ def test_configuration_without_query(self): } # Test that only 'query' configurations are supported # nor 'copy','load','extract' - with tm.assertRaises(ValueError): + with pytest.raises(ValueError): gbq.read_gbq(sql_statement, project_id=_get_project_id(), private_key=_get_private_key_path(), configuration=config) @@ -1034,12 +1035,12 @@ def test_upload_data_if_table_exists_fail(self): self.table.create(TABLE_ID + test_id, gbq._generate_bq_schema(df)) # Test the default value of if_exists is 'fail' - with tm.assertRaises(gbq.TableCreationError): + with pytest.raises(gbq.TableCreationError): gbq.to_gbq(df, self.destination_table + test_id, _get_project_id(), private_key=_get_private_key_path()) # Test the if_exists parameter with value 'fail' - with tm.assertRaises(gbq.TableCreationError): + with pytest.raises(gbq.TableCreationError): gbq.to_gbq(df, self.destination_table + test_id, _get_project_id(), if_exists='fail', private_key=_get_private_key_path()) @@ -1066,7 +1067,7 @@ def test_upload_data_if_table_exists_append(self): assert result['num_rows'][0] == test_size * 2 # Try inserting with a different schema, confirm failure - with tm.assertRaises(gbq.InvalidSchema): + with pytest.raises(gbq.InvalidSchema): gbq.to_gbq(df_different_schema, self.destination_table + test_id, _get_project_id(), if_exists='append', private_key=_get_private_key_path()) @@ -1100,7 +1101,7 @@ def test_upload_data_if_table_exists_raises_value_error(self): df = make_mixed_dataframe_v2(test_size) # Test invalid value for if_exists parameter raises value error - with tm.assertRaises(ValueError): + with pytest.raises(ValueError): gbq.to_gbq(df, self.destination_table + test_id, _get_project_id(), if_exists='xxxxx', private_key=_get_private_key_path()) @@ -1114,7 +1115,7 @@ def test_google_upload_errors_should_raise_exception(self): 'times': [test_timestamp, test_timestamp]}, index=range(2)) - with tm.assertRaises(gbq.StreamingInsertError): + with pytest.raises(gbq.StreamingInsertError): gbq.to_gbq(bad_df, self.destination_table + test_id, _get_project_id(), private_key=_get_private_key_path()) From 4e9002d6207eae66e08928fa135d335f762b70e9 Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Fri, 19 May 2017 12:51:53 -0700 Subject: [PATCH 3/3] MAINT: pandas.util.testing.assert_equals removed This method was removed in https://github.com/pandas-dev/pandas/pull/16017 in favor of pytest.raises. --- pandas_gbq/tests/test_gbq.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pandas_gbq/tests/test_gbq.py b/pandas_gbq/tests/test_gbq.py index 07c4e68a..2ca57b16 100644 --- a/pandas_gbq/tests/test_gbq.py +++ b/pandas_gbq/tests/test_gbq.py @@ -9,7 +9,6 @@ import logging import numpy as np -import pytest from distutils.version import StrictVersion from pandas import compat @@ -387,23 +386,23 @@ def test_import_google_api_python_client(self): def test_should_return_bigquery_integers_as_python_ints(self): result = gbq._parse_entry(1, 'INTEGER') - tm.assert_equal(result, int(1)) + assert result == int(1) def test_should_return_bigquery_floats_as_python_floats(self): result = gbq._parse_entry(1, 'FLOAT') - tm.assert_equal(result, float(1)) + assert result == float(1) def test_should_return_bigquery_timestamps_as_numpy_datetime(self): result = gbq._parse_entry('0e9', 'TIMESTAMP') - tm.assert_equal(result, np_datetime64_compat('1970-01-01T00:00:00Z')) + assert result == np_datetime64_compat('1970-01-01T00:00:00Z') def test_should_return_bigquery_booleans_as_python_booleans(self): result = gbq._parse_entry('false', 'BOOLEAN') - tm.assert_equal(result, False) + assert not result def test_should_return_bigquery_strings_as_python_strings(self): result = gbq._parse_entry('STRING', 'STRING') - tm.assert_equal(result, 'STRING') + assert result == 'STRING' def test_to_gbq_should_fail_if_invalid_table_name_passed(self): with pytest.raises(gbq.NotFoundException): @@ -709,7 +708,7 @@ def test_index_column(self): private_key=_get_private_key_path()) correct_frame = DataFrame( {'string_1': ['a'], 'string_2': ['b']}).set_index("string_1") - tm.assert_equal(result_frame.index.name, correct_frame.index.name) + assert result_frame.index.name == correct_frame.index.name def test_column_order(self): query = "SELECT 'a' AS string_1, 'b' AS string_2, 'c' AS string_3"