Skip to content

Commit 2b3ae1d

Browse files
committed
restore imports
1 parent aa63411 commit 2b3ae1d

File tree

4 files changed

+52
-31
lines changed

4 files changed

+52
-31
lines changed

pandas_gbq/gbq.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,39 @@
1111
from pandas_gbq.contexts import context
1212
from pandas_gbq.exceptions import (
1313
DatasetCreationError,
14+
GenericGBQException,
1415
InvalidColumnOrder,
1516
InvalidIndexColumn,
17+
InvalidPageToken,
18+
InvalidSchema,
1619
NotFoundException,
20+
QueryTimeout,
1721
TableCreationError,
1822
)
1923
from pandas_gbq.features import FEATURES
20-
from pandas_gbq.gbq_connector import GbqConnector
24+
from pandas_gbq.gbq_connector import GbqConnector, create_user_agent
2125
import pandas_gbq.schema
2226
import pandas_gbq.schema.pandas_to_bigquery
2327

2428
logger = logging.getLogger(__name__)
2529

2630

31+
__all__ = [
32+
# The following items were originally defined in this module
33+
# Export them here for backward compatibility.
34+
"DatasetCreationError",
35+
"InvalidColumnOrder",
36+
"InvalidIndexColumn",
37+
"InvalidPageToken",
38+
"InvalidSchema",
39+
"NotFoundException",
40+
"TableCreationError",
41+
"GenericGBQException",
42+
"QueryTimeout",
43+
"create_user_agent",
44+
]
45+
46+
2747
def _test_google_api_imports():
2848
try:
2949
import packaging # noqa

tests/system/test_gbq.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import pytest
1717
import pytz
1818

19-
from pandas_gbq import exceptions, gbq
19+
from pandas_gbq import gbq
2020
import pandas_gbq.schema
2121

2222
TABLE_ID = "new_test"
@@ -195,7 +195,7 @@ def test_read_gbq_raises_invalid_column_order(self, project_id):
195195
col_order = ["string_aaa", "string_1", "string_2"]
196196

197197
# Column string_aaa does not exist. Should raise InvalidColumnOrder
198-
with pytest.raises(exceptions.InvalidColumnOrder):
198+
with pytest.raises(gbq.InvalidColumnOrder):
199199
gbq.read_gbq(
200200
query,
201201
project_id=project_id,
@@ -227,7 +227,7 @@ def test_read_gbq_raises_invalid_index_column(self, project_id):
227227
col_order = ["string_3", "string_2"]
228228

229229
# Column string_bbb does not exist. Should raise InvalidIndexColumn
230-
with pytest.raises(exceptions.InvalidIndexColumn):
230+
with pytest.raises(gbq.InvalidIndexColumn):
231231
gbq.read_gbq(
232232
query,
233233
project_id=project_id,
@@ -238,7 +238,7 @@ def test_read_gbq_raises_invalid_index_column(self, project_id):
238238
)
239239

240240
def test_malformed_query(self, project_id):
241-
with pytest.raises(exceptions.GenericGBQException):
241+
with pytest.raises(gbq.GenericGBQException):
242242
gbq.read_gbq(
243243
"SELCET * FORM [publicdata:samples.shakespeare]",
244244
project_id=project_id,
@@ -247,7 +247,7 @@ def test_malformed_query(self, project_id):
247247
)
248248

249249
def test_bad_project_id(self):
250-
with pytest.raises(exceptions.GenericGBQException):
250+
with pytest.raises(gbq.GenericGBQException):
251251
gbq.read_gbq(
252252
"SELCET * FROM [publicdata:samples.shakespeare]",
253253
project_id="not-my-project",
@@ -256,7 +256,7 @@ def test_bad_project_id(self):
256256
)
257257

258258
def test_bad_table_name(self, project_id):
259-
with pytest.raises(exceptions.GenericGBQException):
259+
with pytest.raises(gbq.GenericGBQException):
260260
gbq.read_gbq(
261261
"SELECT * FROM [publicdata:samples.nope]",
262262
project_id=project_id,
@@ -316,7 +316,7 @@ def test_legacy_sql(self, project_id):
316316

317317
# Test that a legacy sql statement fails when
318318
# setting dialect='standard'
319-
with pytest.raises(exceptions.GenericGBQException):
319+
with pytest.raises(gbq.GenericGBQException):
320320
gbq.read_gbq(
321321
legacy_sql,
322322
project_id=project_id,
@@ -341,7 +341,7 @@ def test_standard_sql(self, project_id):
341341

342342
# Test that a standard sql statement fails when using
343343
# the legacy SQL dialect.
344-
with pytest.raises(exceptions.GenericGBQException):
344+
with pytest.raises(gbq.GenericGBQException):
345345
gbq.read_gbq(
346346
standard_sql,
347347
project_id=project_id,
@@ -485,7 +485,7 @@ def test_timeout_configuration(self, project_id):
485485
{"query": {"useQueryCache": False}, "jobTimeoutMs": 401},
486486
]
487487
for config in configs:
488-
with pytest.raises(exceptions.QueryTimeout):
488+
with pytest.raises(gbq.QueryTimeout):
489489
gbq.read_gbq(
490490
sql_statement,
491491
project_id=project_id,
@@ -507,7 +507,7 @@ def test_timeout_configuration(self, project_id):
507507
]
508508

509509
for config in configs:
510-
with pytest.raises(exceptions.QueryTimeout):
510+
with pytest.raises(gbq.QueryTimeout):
511511
gbq.read_gbq(
512512
sql_statement,
513513
project_id=project_id,
@@ -741,7 +741,7 @@ def test_upload_data_if_table_exists_fail(self, project_id):
741741
)
742742

743743
# Test the default value of if_exists == 'fail'
744-
with pytest.raises(exceptions.TableCreationError):
744+
with pytest.raises(gbq.TableCreationError):
745745
gbq.to_gbq(
746746
df,
747747
self.destination_table + test_id,
@@ -750,7 +750,7 @@ def test_upload_data_if_table_exists_fail(self, project_id):
750750
)
751751

752752
# Test the if_exists parameter with value 'fail'
753-
with pytest.raises(exceptions.TableCreationError):
753+
with pytest.raises(gbq.TableCreationError):
754754
gbq.to_gbq(
755755
df,
756756
self.destination_table + test_id,
@@ -794,7 +794,7 @@ def test_upload_data_if_table_exists_append(self, project_id):
794794
assert result["num_rows"][0] == test_size * 2
795795

796796
# Try inserting with a different schema, confirm failure
797-
with pytest.raises(exceptions.InvalidSchema):
797+
with pytest.raises(gbq.InvalidSchema):
798798
gbq.to_gbq(
799799
df_different_schema,
800800
self.destination_table + test_id,
@@ -1029,7 +1029,7 @@ def test_upload_data_with_invalid_user_schema_raises_error(self, project_id):
10291029
{"name": "D", "type": "FLOAT"},
10301030
]
10311031
destination_table = self.destination_table + test_id
1032-
with pytest.raises(exceptions.GenericGBQException):
1032+
with pytest.raises(gbq.GenericGBQException):
10331033
gbq.to_gbq(
10341034
df,
10351035
destination_table,
@@ -1047,7 +1047,7 @@ def test_upload_data_with_missing_schema_fields_raises_error(self, project_id):
10471047
{"name": "C", "type": "FLOAT"},
10481048
]
10491049
destination_table = self.destination_table + test_id
1050-
with pytest.raises(exceptions.GenericGBQException):
1050+
with pytest.raises(gbq.GenericGBQException):
10511051
gbq.to_gbq(
10521052
df,
10531053
destination_table,
@@ -1193,7 +1193,7 @@ def test_create_dataset(bigquery_client, gbq_dataset, random_dataset_id, project
11931193

11941194
def test_create_dataset_already_exists(gbq_dataset, random_dataset_id):
11951195
gbq_dataset.create(random_dataset_id)
1196-
with pytest.raises(exceptions.DatasetCreationError):
1196+
with pytest.raises(gbq.DatasetCreationError):
11971197
gbq_dataset.create(random_dataset_id)
11981198

11991199

@@ -1218,7 +1218,7 @@ def test_create_table(gbq_table):
12181218
def test_create_table_already_exists(gbq_table):
12191219
schema = gbq._generate_bq_schema(make_mixed_dataframe_v1())
12201220
gbq_table.create("test_create_table_exists", schema)
1221-
with pytest.raises(exceptions.TableCreationError):
1221+
with pytest.raises(gbq.TableCreationError):
12221222
gbq_table.create("test_create_table_exists", schema)
12231223

12241224

tests/unit/test_gbq.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
from pandas import DataFrame
2020
import pytest
2121

22-
from pandas_gbq import exceptions, gbq, gbq_connector
22+
from pandas_gbq import gbq, gbq_connector
2323
import pandas_gbq.constants
24+
import pandas_gbq.exceptions
2425
import pandas_gbq.features
2526
from pandas_gbq.features import FEATURES
2627

@@ -221,7 +222,7 @@ def test_GbqConnector_process_http_error_transforms_timeout():
221222
original = google.api_core.exceptions.GoogleAPICallError(
222223
"Job execution was cancelled: Job timed out after 0s"
223224
)
224-
with pytest.raises(exceptions.QueryTimeout):
225+
with pytest.raises(gbq.QueryTimeout):
225226
gbq.GbqConnector.process_http_error(original)
226227

227228

@@ -389,7 +390,7 @@ def test_dataset_exists_translates_exception(mock_bigquery_client):
389390
mock_bigquery_client.get_dataset.side_effect = (
390391
google.api_core.exceptions.InternalServerError("something went wrong")
391392
)
392-
with pytest.raises(exceptions.GenericGBQException):
393+
with pytest.raises(gbq.GenericGBQException):
393394
connector.exists("not_gonna_work")
394395

395396

@@ -412,7 +413,7 @@ def test_table_create_translates_exception(mock_bigquery_client):
412413
mock_bigquery_client.create_table.side_effect = (
413414
google.api_core.exceptions.InternalServerError("something went wrong")
414415
)
415-
with pytest.raises(exceptions.GenericGBQException):
416+
with pytest.raises(gbq.GenericGBQException):
416417
connector.create(
417418
"not_gonna_work", {"fields": [{"name": "f", "type": "STRING"}]}
418419
)
@@ -434,7 +435,7 @@ def test_table_delete_translates_exception(mock_bigquery_client):
434435
mock_bigquery_client.delete_table.side_effect = (
435436
google.api_core.exceptions.InternalServerError("something went wrong")
436437
)
437-
with pytest.raises(exceptions.GenericGBQException):
438+
with pytest.raises(gbq.GenericGBQException):
438439
connector.delete("not_gonna_work")
439440

440441

@@ -460,7 +461,7 @@ def test_table_exists_translates_exception(mock_bigquery_client):
460461
mock_bigquery_client.get_table.side_effect = (
461462
google.api_core.exceptions.InternalServerError("something went wrong")
462463
)
463-
with pytest.raises(exceptions.GenericGBQException):
464+
with pytest.raises(gbq.GenericGBQException):
464465
connector.exists("not_gonna_work")
465466

466467

@@ -919,7 +920,7 @@ def test_read_gbq_with_list_rows_error_translates_exception(
919920
google.api_core.exceptions.NotFound("table not found"),
920921
)
921922

922-
with pytest.raises(exceptions.GenericGBQException, match="table not found"):
923+
with pytest.raises(gbq.GenericGBQException, match="table not found"):
923924
gbq.read_gbq(
924925
"my-project.my_dataset.read_gbq_table",
925926
credentials=mock_service_account_credentials,

tests/unit/test_to_gbq.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pandas import DataFrame
99
import pytest
1010

11-
from pandas_gbq import exceptions, gbq
11+
from pandas_gbq import gbq
1212

1313

1414
class FakeDataFrame:
@@ -53,7 +53,7 @@ def test_to_gbq_create_dataset_translates_exception(mock_bigquery_client):
5353
google.api_core.exceptions.InternalServerError("something went wrong")
5454
)
5555

56-
with pytest.raises(exceptions.GenericGBQException):
56+
with pytest.raises(gbq.GenericGBQException):
5757
gbq.to_gbq(DataFrame([[1]]), "my_dataset.my_table", project_id="1234")
5858

5959

@@ -67,7 +67,7 @@ def test_to_gbq_load_method_translates_exception(
6767
"error loading data"
6868
)
6969

70-
with pytest.raises(exceptions.GenericGBQException):
70+
with pytest.raises(gbq.GenericGBQException):
7171
gbq.to_gbq(
7272
DataFrame({"int_cole": [1, 2, 3]}),
7373
"my_dataset.my_table",
@@ -111,11 +111,11 @@ def test_to_gbq_with_if_exists_append_mismatch(mock_bigquery_client):
111111
"myproj.my_dataset.my_table",
112112
schema=(SchemaField("col_a", "INTEGER"), SchemaField("col_b", "STRING")),
113113
)
114-
mock_bigquery_client.side_effect = exceptions.InvalidSchema(
114+
mock_bigquery_client.side_effect = gbq.InvalidSchema(
115115
message=r"Provided Schema does not match Table *"
116116
)
117117

118-
with pytest.raises(exceptions.InvalidSchema) as exception_block:
118+
with pytest.raises((gbq.InvalidSchema)) as exception_block:
119119
gbq.to_gbq(
120120
DataFrame({"col_a": [0.25, 1.5, -1.0]}),
121121
"my_dataset.my_table",
@@ -198,7 +198,7 @@ def test_to_gbq_with_if_exists_unknown():
198198
],
199199
)
200200
def test_create_user_agent(user_agent, rfc9110_delimiter, expected):
201-
from pandas_gbq.gbq_connector import create_user_agent
201+
from pandas_gbq.gbq import create_user_agent
202202

203203
result = create_user_agent(user_agent, rfc9110_delimiter)
204204
assert result == expected

0 commit comments

Comments
 (0)