Skip to content

ENH: Add progress_bar_type argument in read_gbq #29858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Dec 8, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ I/O
- Bug in :meth:`DataFrame.to_clipboard` which did not work reliably in ipython (:issue:`22707`)
- Bug in :func:`read_json` where default encoding was not set to ``utf-8`` (:issue:`29565`)
- Bug in :class:`PythonParser` where str and bytes were being mixed when dealing with the decimal field (:issue:`29650`)
- :meth:`read_gbq` now accepts ``progress_bar_type`` to display progress bar while the data downloads. (:issue:`29857`)
-

Plotting
Expand Down
26 changes: 26 additions & 0 deletions pandas/io/gbq.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def read_gbq(
use_bqstorage_api=None,
private_key=None,
verbose=None,
progress_bar_type="tqdm",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's default to None until there have been a few more pandas-gbq releases with this feature.

Suggested change
progress_bar_type="tqdm",
progress_bar_type=None,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed!! thanks!!

):
"""
Load data from Google BigQuery.
Expand Down Expand Up @@ -134,6 +135,29 @@ def read_gbq(
Deprecated in pandas-gbq version 0.4.0. Use the `logging module to
adjust verbosity instead
<https://pandas-gbq.readthedocs.io/en/latest/intro.html#logging>`__.
progress_bar_type : Optional, str
If set, use the `tqdm <https://tqdm.github.io/>`__ library to
display a progress bar while the data downloads. Install the
``tqdm`` package to use this feature.

Possible values of ``progress_bar_type`` include:

``None``
No progress bar.
``'tqdm'``
Use the :func:`tqdm.tqdm` function to print a progress bar
to :data:`sys.stderr`.
``'tqdm_notebook'``
Use the :func:`tqdm.tqdm_notebook` function to display a
progress bar as a Jupyter notebook widget.
``'tqdm_gui'``
Use the :func:`tqdm.tqdm_gui` function to display a
progress bar as a graphical dialog box.

Note that his feature requires version 0.12.0 or later of the
``pandas-gbq`` package. And it requires the ``tqdm`` package.

.. versionadded:: 1.0.0

Returns
-------
Expand All @@ -152,6 +176,8 @@ def read_gbq(
# START: new kwargs. Don't populate unless explicitly set.
if use_bqstorage_api is not None:
kwargs["use_bqstorage_api"] = use_bqstorage_api

kwargs["progress_bar_type"] = progress_bar_type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid breaking people with pandas-gbq < 0.12.0, only populate the progress_bar_type kwargs if explicitly set.

Suggested change
kwargs["progress_bar_type"] = progress_bar_type
if progress_bar_type is not None:
kwargs["progress_bar_type"] = progress_bar_type

Copy link
Member Author

@charlesdong1991 charlesdong1991 Dec 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @tswast for your reviews!!

# END: new kwargs

# START: deprecated kwargs. Don't populate unless explicitly set.
Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/io/test_gbq.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,21 @@ def mock_read_gbq(sql, **kwargs):
assert "use_bqstorage_api" not in captured_kwargs


@pytest.mark.parametrize("progress_bar", [None, "foo"])
def test_read_gbq_progress_bar_type_kwarg(monkeypatch, progress_bar):
# GH 29857
captured_kwargs = {}

def mock_read_gbq(sql, **kwargs):
captured_kwargs.update(kwargs)
return DataFrame([[1.0]])

monkeypatch.setattr("pandas_gbq.read_gbq", mock_read_gbq)
pd.read_gbq("SELECT 1", progress_bar_type=progress_bar)

assert "progress_bar_type" in captured_kwargs


@pytest.mark.single
class TestToGBQIntegrationWithServiceAccountKeyPath:
@classmethod
Expand Down