Skip to content

Commit

Permalink
Fix: Refactors code to account for a tdqm code deprecation (#1357)
Browse files Browse the repository at this point in the history
* tests some options

* refactors to use tqdm.* notation

* refactors tqdm function calls to account for deprecation warning

* refactors _tqdm_helpers to account for tqdm deprecation warnings

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* removes an extraneous reference to ipywidgets

* removes unneeded import

* removes import and fixes linting error

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
chalmerlowe and gcf-owl-bot[bot] committed Sep 19, 2022
1 parent 86aa393 commit 1369a9d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion google/cloud/bigquery/_tqdm_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

try:
import tqdm # type: ignore

except ImportError: # pragma: NO COVER
tqdm = None

Expand All @@ -48,7 +49,7 @@ def get_progress_bar(progress_bar_type, description, total, unit):
if progress_bar_type == "tqdm":
return tqdm.tqdm(desc=description, total=total, unit=unit)
elif progress_bar_type == "tqdm_notebook":
return tqdm.tqdm_notebook(desc=description, total=total, unit=unit)
return tqdm.notebook.tqdm(desc=description, total=total, unit=unit)
elif progress_bar_type == "tqdm_gui":
return tqdm.tqdm_gui(desc=description, total=total, unit=unit)
except (KeyError, TypeError):
Expand Down
15 changes: 10 additions & 5 deletions tests/unit/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
geopandas = None

try:
from tqdm import tqdm
import tqdm
from tqdm.std import TqdmDeprecationWarning

except (ImportError, AttributeError): # pragma: NO COVER
tqdm = None

Expand Down Expand Up @@ -2798,7 +2800,7 @@ def test_to_arrow_w_bqstorage_no_streams(self):

@unittest.skipIf(tqdm is None, "Requires `tqdm`")
@mock.patch("tqdm.tqdm_gui")
@mock.patch("tqdm.tqdm_notebook")
@mock.patch("tqdm.notebook.tqdm")
@mock.patch("tqdm.tqdm")
def test_to_arrow_progress_bar(self, tqdm_mock, tqdm_notebook_mock, tqdm_gui_mock):
from google.cloud.bigquery.schema import SchemaField
Expand Down Expand Up @@ -3146,7 +3148,7 @@ def test_to_dataframe_datetime_out_of_pyarrow_bounds(self):
@unittest.skipIf(pandas is None, "Requires `pandas`")
@unittest.skipIf(tqdm is None, "Requires `tqdm`")
@mock.patch("tqdm.tqdm_gui")
@mock.patch("tqdm.tqdm_notebook")
@mock.patch("tqdm.notebook.tqdm")
@mock.patch("tqdm.tqdm")
def test_to_dataframe_progress_bar(
self, tqdm_mock, tqdm_notebook_mock, tqdm_gui_mock
Expand Down Expand Up @@ -3249,7 +3251,7 @@ def test_to_dataframe_no_tqdm(self):
@unittest.skipIf(pandas is None, "Requires `pandas`")
@unittest.skipIf(tqdm is None, "Requires `tqdm`")
@mock.patch("tqdm.tqdm_gui", new=None) # will raise TypeError on call
@mock.patch("tqdm.tqdm_notebook", new=None) # will raise TypeError on call
@mock.patch("tqdm.notebook.tqdm", new=None) # will raise TypeError on call
@mock.patch("tqdm.tqdm", new=None) # will raise TypeError on call
def test_to_dataframe_tqdm_error(self):
from google.cloud.bigquery.schema import SchemaField
Expand Down Expand Up @@ -3281,7 +3283,10 @@ def test_to_dataframe_tqdm_error(self):
# Warn that a progress bar was requested, but creating the tqdm
# progress bar failed.
for warning in warned:
self.assertIs(warning.category, UserWarning)
self.assertIn(
warning.category,
[UserWarning, DeprecationWarning, TqdmDeprecationWarning],
)

@unittest.skipIf(pandas is None, "Requires `pandas`")
def test_to_dataframe_w_empty_results(self):
Expand Down

0 comments on commit 1369a9d

Please sign in to comment.