diff --git a/tests/system/test_gbq.py b/tests/system/test_gbq.py index a6f371af..33369557 100644 --- a/tests/system/test_gbq.py +++ b/tests/system/test_gbq.py @@ -868,26 +868,27 @@ def test_array_agg(self, project_id): ), ) - def test_array_of_floats(self, private_key_path, project_id): + def test_array_of_floats(self, project_id): query = """select [1.1, 2.2, 3.3] as a, 4 as b""" df = gbq.read_gbq( query, project_id=project_id, - private_key=private_key_path, + credentials=self.credentials, dialect="standard", ) tm.assert_frame_equal( df, DataFrame([[[1.1, 2.2, 3.3], 4]], columns=["a", "b"]) ) - def test_tokyo(self, tokyo_dataset, tokyo_table, private_key_path): + def test_tokyo(self, tokyo_dataset, tokyo_table, project_id): df = gbq.read_gbq( "SELECT MAX(year) AS max_year FROM {}.{}".format( tokyo_dataset, tokyo_table ), dialect="standard", location="asia-northeast1", - private_key=private_key_path, + project_id=project_id, + credentials=self.credentials, ) assert df["max_year"][0] >= 2000 @@ -1401,7 +1402,17 @@ def test_upload_data_with_timestamp(self, project_id): index=range(test_size), columns=list("ABCD"), ) - df["times"] = np.datetime64("2018-03-13T05:40:45.348318Z") + df["times"] = pandas.Series( + [ + "2018-03-13T05:40:45.348318", + "2018-04-13T05:40:45.348318", + "2018-05-13T05:40:45.348318", + "2018-06-13T05:40:45.348318", + "2018-07-13T05:40:45.348318", + "2018-08-13T05:40:45.348318", + ], + dtype="datetime64[ns]", + ).dt.tz_localize("UTC") gbq.to_gbq( df, @@ -1421,7 +1432,7 @@ def test_upload_data_with_timestamp(self, project_id): expected = df["times"].sort_values() result = result_df["times"].sort_values() - tm.assert_numpy_array_equal(expected.values, result.values) + tm.assert_series_equal(expected, result) def test_upload_data_with_different_df_and_user_schema(self, project_id): df = tm.makeMixedDataFrame() diff --git a/tests/unit/test_gbq.py b/tests/unit/test_gbq.py index f2e52462..0452bf88 100644 --- a/tests/unit/test_gbq.py +++ b/tests/unit/test_gbq.py @@ -121,9 +121,8 @@ def test_to_gbq_with_no_project_id_given_should_fail(monkeypatch): pydata_google_auth, "default", mock_get_credentials_no_project ) - with pytest.raises(ValueError) as exception: + with pytest.raises(ValueError, match="Could not determine project ID"): gbq.to_gbq(DataFrame([[1]]), "dataset.tablename") - assert "Could not determine project ID" in str(exception) def test_to_gbq_with_verbose_new_pandas_warns_deprecation(min_bq_version): @@ -280,9 +279,8 @@ def test_read_gbq_with_no_project_id_given_should_fail(monkeypatch): pydata_google_auth, "default", mock_get_credentials_no_project ) - with pytest.raises(ValueError) as exception: + with pytest.raises(ValueError, match="Could not determine project ID"): gbq.read_gbq("SELECT 1", dialect="standard") - assert "Could not determine project ID" in str(exception) def test_read_gbq_with_inferred_project_id(monkeypatch): @@ -311,13 +309,12 @@ def test_read_gbq_with_inferred_project_id_from_service_account_credentials( def test_read_gbq_without_inferred_project_id_from_compute_engine_credentials( mock_compute_engine_credentials ): - with pytest.raises(ValueError) as exception: + with pytest.raises(ValueError, match="Could not determine project ID"): gbq.read_gbq( "SELECT 1", dialect="standard", credentials=mock_compute_engine_credentials, ) - assert "Could not determine project ID" in str(exception) def test_read_gbq_with_invalid_private_key_json_should_fail(): @@ -469,9 +466,8 @@ def test_read_gbq_with_private_key_old_pandas_no_warnings( def test_read_gbq_with_invalid_dialect(): - with pytest.raises(ValueError) as excinfo: + with pytest.raises(ValueError, match="is not valid for dialect"): gbq.read_gbq("SELECT 1", dialect="invalid") - assert "is not valid for dialect" in str(excinfo.value) def test_generate_bq_schema_deprecated():