Skip to content

Commit 13fbf92

Browse files
return the cost (in GB) if dry run is set to True
1 parent d268a62 commit 13fbf92

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

pandas_gbq/gbq_connector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def run_query(
270270
dtypes = kwargs.get("dtypes")
271271

272272
if dry_run:
273-
return rows_iter
273+
return rows_iter.total_bytes_processed / 1024**3
274274

275275
return self._download_results(
276276
rows_iter,

tests/system/test_gbq.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -658,16 +658,16 @@ def test_columns_and_col_order_raises_error(self, project_id):
658658

659659
def test_read_gbq_with_dry_run(self, project_id):
660660
query = "SELECT 1"
661-
job = gbq.read_gbq(
661+
cost = gbq.read_gbq(
662662
query,
663663
project_id=project_id,
664664
credentials=self.credentials,
665665
dialect="standard",
666666
dry_run=True,
667667
)
668-
assert job.dry_run
669-
assert job.state == "DONE"
670-
assert job.total_bytes_processed > 0
668+
assert isinstance(cost, float)
669+
assert cost > 0
670+
671671

672672

673673
class TestToGBQIntegration(object):

tests/unit/test_gbq.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,8 +939,10 @@ def test_run_query_with_dml_query(mock_bigquery_client, mock_query_job):
939939
mock_bigquery_client.list_rows.assert_not_called()
940940

941941

942-
def test_read_gbq_with_dry_run(mock_bigquery_client):
943-
gbq.read_gbq("SELECT 1", project_id="my-project", dry_run=True)
942+
def test_read_gbq_with_dry_run(mock_bigquery_client, mock_query_job):
943+
type(mock_query_job).total_bytes_processed = mock.PropertyMock(return_value=12345)
944+
cost = gbq.read_gbq("SELECT 1", project_id="my-project", dry_run=True)
944945
_, kwargs = mock_bigquery_client.query.call_args
945946
job_config = kwargs["job_config"]
946947
assert job_config.dry_run is True
948+
assert cost == 12345 / 1024**3

0 commit comments

Comments
 (0)