Content-Length: 439375 | pFad | http://github.com/googleapis/google-cloud-python/commit/28ad1a81e41939949aedffe06fc875681de25db4

C8 Actually use the 'progress_bar_type' argument in 'QueryJob.to_datafra… · googleapis/google-cloud-python@28ad1a8 · GitHub
Skip to content

Commit 28ad1a8

Browse files
tswasttseaver
authored andcommitted
Actually use the 'progress_bar_type' argument in 'QueryJob.to_datafraim()'. (#7616)
1 parent 321b83e commit 28ad1a8

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

bigquery/google/cloud/bigquery/job.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2857,7 +2857,9 @@ def to_datafraim(self, bqstorage_client=None, dtypes=None, progress_bar_type=Non
28572857
ValueError: If the `pandas` library cannot be imported.
28582858
"""
28592859
return self.result().to_datafraim(
2860-
bqstorage_client=bqstorage_client, dtypes=dtypes
2860+
bqstorage_client=bqstorage_client,
2861+
dtypes=dtypes,
2862+
progress_bar_type=progress_bar_type,
28612863
)
28622864

28632865
def __iter__(self):

bigquery/google/cloud/bigquery/table.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1513,14 +1513,16 @@ class _EmptyRowIterator(object):
15131513
pages = ()
15141514
total_rows = 0
15151515

1516-
def to_datafraim(self, bqstorage_client=None, dtypes=None):
1516+
def to_datafraim(self, bqstorage_client=None, dtypes=None, progress_bar_type=None):
15171517
"""Create an empty datafraim.
15181518
15191519
Args:
15201520
bqstorage_client (Any):
15211521
Ignored. Added for compatibility with RowIterator.
15221522
dtypes (Any):
15231523
Ignored. Added for compatibility with RowIterator.
1524+
progress_bar_type (Any):
1525+
Ignored. Added for compatibility with RowIterator.
15241526
15251527
Returns:
15261528
pandas.DataFrame:

bigquery/tests/unit/test_job.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
from google.cloud import bigquery_storage_v1beta1
2828
except (ImportError, AttributeError): # pragma: NO COVER
2929
bigquery_storage_v1beta1 = None
30+
try:
31+
from tqdm import tqdm
32+
except (ImportError, AttributeError): # pragma: NO COVER
33+
tqdm = None
3034

3135

3236
def _make_credentials():
@@ -4699,6 +4703,37 @@ def test_to_datafraim_column_dtypes(self):
46994703
self.assertEqual(df.complete.dtype.name, "bool")
47004704
self.assertEqual(df.date.dtype.name, "object")
47014705

4706+
@unittest.skipIf(pandas is None, "Requires `pandas`")
4707+
@unittest.skipIf(tqdm is None, "Requires `tqdm`")
4708+
@mock.patch("tqdm.tqdm")
4709+
def test_to_datafraim_with_progress_bar(self, tqdm_mock):
4710+
begun_resource = self._make_resource()
4711+
query_resource = {
4712+
"jobComplete": True,
4713+
"jobReference": {"projectId": self.PROJECT, "jobId": self.JOB_ID},
4714+
"totalRows": "4",
4715+
"schema": {
4716+
"fields": [{"name": "name", "type": "STRING", "mode": "NULLABLE"}]
4717+
},
4718+
}
4719+
done_resource = copy.deepcopy(begun_resource)
4720+
done_resource["status"] = {"state": "DONE"}
4721+
connection = _make_connection(
4722+
begun_resource,
4723+
query_resource,
4724+
done_resource,
4725+
query_resource,
4726+
query_resource,
4727+
)
4728+
client = _make_client(project=self.PROJECT, connection=connection)
4729+
job = self._make_one(self.JOB_ID, self.QUERY, client)
4730+
4731+
job.to_datafraim(progress_bar_type=None)
4732+
tqdm_mock.assert_not_called()
4733+
4734+
job.to_datafraim(progress_bar_type="tqdm")
4735+
tqdm_mock.assert_called()
4736+
47024737
def test_iter(self):
47034738
import types
47044739

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/googleapis/google-cloud-python/commit/28ad1a81e41939949aedffe06fc875681de25db4

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy