@@ -436,7 +436,9 @@ def process_http_error(ex):
436
436
437
437
raise GenericGBQException ("Reason: {0}" .format (ex ))
438
438
439
- def run_query (self , query , max_results = None , ** kwargs ):
439
+ def run_query (
440
+ self , query , max_results = None , progress_bar_type = None , ** kwargs
441
+ ):
440
442
from concurrent .futures import TimeoutError
441
443
from google .auth .exceptions import RefreshError
442
444
from google .cloud import bigquery
@@ -526,9 +528,15 @@ def run_query(self, query, max_results=None, **kwargs):
526
528
)
527
529
)
528
530
529
- return self ._download_results (query_reply , max_results = max_results )
531
+ return self ._download_results (
532
+ query_reply ,
533
+ max_results = max_results ,
534
+ progress_bar_type = progress_bar_type ,
535
+ )
530
536
531
- def _download_results (self , query_job , max_results = None ):
537
+ def _download_results (
538
+ self , query_job , max_results = None , progress_bar_type = None
539
+ ):
532
540
# No results are desired, so don't bother downloading anything.
533
541
if max_results == 0 :
534
542
return None
@@ -552,7 +560,9 @@ def _download_results(self, query_job, max_results=None):
552
560
schema_fields = [field .to_api_repr () for field in rows_iter .schema ]
553
561
nullsafe_dtypes = _bqschema_to_nullsafe_dtypes (schema_fields )
554
562
df = rows_iter .to_dataframe (
555
- dtypes = nullsafe_dtypes , bqstorage_client = bqstorage_client
563
+ dtypes = nullsafe_dtypes ,
564
+ bqstorage_client = bqstorage_client ,
565
+ progress_bar_type = progress_bar_type ,
556
566
)
557
567
558
568
if df .empty :
@@ -833,6 +843,7 @@ def read_gbq(
833
843
max_results = None ,
834
844
verbose = None ,
835
845
private_key = None ,
846
+ progress_bar_type = "tqdm" ,
836
847
):
837
848
r"""Load data from Google BigQuery using google-cloud-python
838
849
@@ -952,6 +963,23 @@ def read_gbq(
952
963
or string contents. This is useful for remote server
953
964
authentication (eg. Jupyter/IPython notebook on remote host).
954
965
966
+ progress_bar_type (Optional[str]):
967
+ If set, use the `tqdm <https://tqdm.github.io/>`_ library to
968
+ display a progress bar while the data downloads. Install the
969
+ ``tqdm`` package to use this feature.
970
+ Possible values of ``progress_bar_type`` include:
971
+ ``None``
972
+ No progress bar.
973
+ ``'tqdm'``
974
+ Use the :func:`tqdm.tqdm` function to print a progress bar
975
+ to :data:`sys.stderr`.
976
+ ``'tqdm_notebook'``
977
+ Use the :func:`tqdm.tqdm_notebook` function to display a
978
+ progress bar as a Jupyter notebook widget.
979
+ ``'tqdm_gui'``
980
+ Use the :func:`tqdm.tqdm_gui` function to display a
981
+ progress bar as a graphical dialog box.
982
+
955
983
Returns
956
984
-------
957
985
df: DataFrame
@@ -996,7 +1024,10 @@ def read_gbq(
996
1024
)
997
1025
998
1026
final_df = connector .run_query (
999
- query , configuration = configuration , max_results = max_results
1027
+ query ,
1028
+ configuration = configuration ,
1029
+ max_results = max_results ,
1030
+ progress_bar_type = progress_bar_type ,
1000
1031
)
1001
1032
1002
1033
# Reindex the DataFrame on the provided column
0 commit comments