-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
BigQuery: Add tqdm progress bar for downloads #7552
Changes from 2 commits
d309212
c6efe1b
b23d581
3c1f008
c0e3a39
0693789
9506caa
a7d9d59
25f4e13
4aafefe
62e3d58
bed0694
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1334,8 +1334,21 @@ def _to_dataframe_tabledata_list(self, dtypes): | |
"""Use (slower, but free) tabledata.list to construct a DataFrame.""" | ||
column_names = [field.name for field in self.schema] | ||
frames = [] | ||
|
||
# report progress if tqdm installed | ||
try: | ||
from tqdm import tqdm | ||
pbar = tqdm(desc="Downloading", total=self.total_rows, unit="rows") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this do something sensible when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I'll update |
||
except (ImportError, KeyError, TypeError): | ||
pbar = None | ||
|
||
for page in iter(self.pages): | ||
frames.append(self._to_dataframe_dtypes(page, column_names, dtypes)) | ||
|
||
if pbar is not None: | ||
# update progress bar with number of rows in last frame | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is unnecessary, since it just states what is happening in the next line. Comments in this codebase should state why or explain something that looks "wrong". This comment indicates to me that we need to rename
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome feedback, thank you :) |
||
pbar.update(len(frames[-1])) | ||
|
||
return pandas.concat(frames) | ||
|
||
def _to_dataframe_bqstorage(self, bqstorage_client, dtypes): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We aim for 100% unit test coverage, so could you follow the pattern that we do with the optional pandas dependency where we import it at the top of the module and catch import errors there?
That way we can install tqdm for our unit tests but then mock it out in another test to check that it doesn't fail when the tqdm module can't be loaded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!