Skip to content

Commit 91cd925

Browse files
charlesdong1991proost
authored andcommitted
ENH: Add progress_bar_type argument in read_gbq (pandas-dev#29858)
1 parent 5f16b1f commit 91cd925

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

doc/source/whatsnew/v1.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ I/O
773773
- Bug in :meth:`DataFrame.to_clipboard` which did not work reliably in ipython (:issue:`22707`)
774774
- Bug in :func:`read_json` where default encoding was not set to ``utf-8`` (:issue:`29565`)
775775
- Bug in :class:`PythonParser` where str and bytes were being mixed when dealing with the decimal field (:issue:`29650`)
776+
- :meth:`read_gbq` now accepts ``progress_bar_type`` to display progress bar while the data downloads. (:issue:`29857`)
776777
-
777778

778779
Plotting

pandas/io/gbq.py

+28
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def read_gbq(
2727
use_bqstorage_api=None,
2828
private_key=None,
2929
verbose=None,
30+
progress_bar_type=None,
3031
):
3132
"""
3233
Load data from Google BigQuery.
@@ -134,6 +135,30 @@ def read_gbq(
134135
Deprecated in pandas-gbq version 0.4.0. Use the `logging module to
135136
adjust verbosity instead
136137
<https://pandas-gbq.readthedocs.io/en/latest/intro.html#logging>`__.
138+
progress_bar_type : Optional, str
139+
If set, use the `tqdm <https://tqdm.github.io/>`__ library to
140+
display a progress bar while the data downloads. Install the
141+
``tqdm`` package to use this feature.
142+
143+
Possible values of ``progress_bar_type`` include:
144+
145+
``None``
146+
No progress bar.
147+
``'tqdm'``
148+
Use the :func:`tqdm.tqdm` function to print a progress bar
149+
to :data:`sys.stderr`.
150+
``'tqdm_notebook'``
151+
Use the :func:`tqdm.tqdm_notebook` function to display a
152+
progress bar as a Jupyter notebook widget.
153+
``'tqdm_gui'``
154+
Use the :func:`tqdm.tqdm_gui` function to display a
155+
progress bar as a graphical dialog box.
156+
157+
Note that his feature requires version 0.12.0 or later of the
158+
``pandas-gbq`` package. And it requires the ``tqdm`` package. Slightly
159+
different than ``pandas-gbq``, here the default is ``None``.
160+
161+
.. versionadded:: 1.0.0
137162
138163
Returns
139164
-------
@@ -152,6 +177,9 @@ def read_gbq(
152177
# START: new kwargs. Don't populate unless explicitly set.
153178
if use_bqstorage_api is not None:
154179
kwargs["use_bqstorage_api"] = use_bqstorage_api
180+
181+
if progress_bar_type is not None:
182+
kwargs["progress_bar_type"] = progress_bar_type
155183
# END: new kwargs
156184

157185
# START: deprecated kwargs. Don't populate unless explicitly set.

pandas/tests/io/test_gbq.py

+18
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,24 @@ def mock_read_gbq(sql, **kwargs):
144144
assert "use_bqstorage_api" not in captured_kwargs
145145

146146

147+
@pytest.mark.parametrize("progress_bar", [None, "foo"])
148+
def test_read_gbq_progress_bar_type_kwarg(monkeypatch, progress_bar):
149+
# GH 29857
150+
captured_kwargs = {}
151+
152+
def mock_read_gbq(sql, **kwargs):
153+
captured_kwargs.update(kwargs)
154+
return DataFrame([[1.0]])
155+
156+
monkeypatch.setattr("pandas_gbq.read_gbq", mock_read_gbq)
157+
pd.read_gbq("SELECT 1", progress_bar_type=progress_bar)
158+
159+
if progress_bar:
160+
assert "progress_bar_type" in captured_kwargs
161+
else:
162+
assert "progress_bar_type" not in captured_kwargs
163+
164+
147165
@pytest.mark.single
148166
class TestToGBQIntegrationWithServiceAccountKeyPath:
149167
@classmethod

0 commit comments

Comments
 (0)