Skip to content

Fix that tqdm_class cannot be passed to tmap and tzip#1148

Merged
casperdcl merged 2 commits intotqdm:develfrom
grst:master
Apr 5, 2021
Merged

Fix that tqdm_class cannot be passed to tmap and tzip#1148
casperdcl merged 2 commits intotqdm:develfrom
grst:master

Conversation

@grst
Copy link
Copy Markdown
Contributor

@grst grst commented Mar 16, 2021

There's currently the issue that tqdm_class cannot be passed to tmap and tzip. This PR fixes the issue and adds tests for it.

Here's a repex of the problem:

from tqdm.contrib import tmap
from tqdm import tqdm       
list(tmap(print, range(10), tqdm_class=tqdm))
---------------------------------------------------------------------------
TqdmKeyError                              Traceback (most recent call last)
<ipython-input-4-62e01f8ad3b6> in <module>
----> 1 list(tmap(print, range(10), tqdm_class=tqdm))

~/anaconda3/lib/python3.7/site-packages/tqdm/contrib/__init__.py in _tmap(function, *sequences, **tqdm_kwargs)
     64     tqdm_class  : [default: tqdm.auto.tqdm].
     65     """
---> 66     for i in _tzip(*sequences, **tqdm_kwargs):
     67         yield function(*i)
     68 

~/anaconda3/lib/python3.7/site-packages/tqdm/contrib/__init__.py in _tzip(iter1, *iter2plus, **tqdm_kwargs)
     52     kwargs = deepcopy(tqdm_kwargs)
     53     tqdm_class = kwargs.pop("tqdm_class", tqdm_auto)
---> 54     for i in zip(tqdm_class(iter1, **tqdm_kwargs), *iter2plus):
     55         yield i
     56 

~/anaconda3/lib/python3.7/site-packages/tqdm/std.py in __init__(self, iterable, desc, total, leave, file, ncols, mininterval, maxinterval, miniters, ascii, disable, unit, unit_scale, dynamic_ncols, smoothing, bar_format, initial, position, postfix, unit_divisor, write_bytes, lock_args, nrows, gui, **kwargs)
    961                     fp_write=getattr(file, 'write', sys.stderr.write))
    962                 if "nested" in kwargs else
--> 963                 TqdmKeyError("Unknown argument(s): " + str(kwargs)))
    964 
    965         # Preprocess the arguments

TqdmKeyError: "Unknown argument(s): {'tqdm_class': <class 'tqdm.std.tqdm'>}"

@grst grst requested a review from casperdcl as a code owner March 16, 2021 17:54
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 16, 2021

Codecov Report

Merging #1148 (c633fc5) into master (bcce20f) will decrease coverage by 0.18%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1148      +/-   ##
==========================================
- Coverage   84.73%   84.55%   -0.19%     
==========================================
  Files          25       25              
  Lines        1651     1651              
  Branches      273      273              
==========================================
- Hits         1399     1396       -3     
- Misses        213      216       +3     
  Partials       39       39              

@casperdcl casperdcl self-assigned this Mar 16, 2021
@casperdcl casperdcl added c1-quick 🕐 Complexity low p0-bug-critical ☢ Exception rasing submodule ⊂ Periphery/subclasses to-merge ↰ Imminent labels Mar 16, 2021
@casperdcl casperdcl added this to the Non-breaking milestone Mar 16, 2021
Comment thread tqdm/contrib/__init__.py
Comment on lines -83 to +84
for i in zip(tqdm_class(iter1, **tqdm_kwargs), *iter2plus):
for i in zip(tqdm_class(iter1, **kwargs), *iter2plus):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

woops; nice catch.

@casperdcl casperdcl changed the base branch from master to devel April 5, 2021 19:05
@casperdcl casperdcl merged commit 9fb0f23 into tqdm:devel Apr 5, 2021
@casperdcl casperdcl mentioned this pull request Apr 5, 2021
bdice added a commit to glotzerlab/signac-flow that referenced this pull request Feb 27, 2022
bdice added a commit to glotzerlab/signac-flow that referenced this pull request Mar 1, 2022
* Fix: tqdm.auto requires ipywidgets for notebook support.

* Update changelog.

* Use tqdm_class to avoid bug in automatic detection.

* Bump tqdm requirement to 4.60.0 for tqdm/tqdm#1148.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c1-quick 🕐 Complexity low p0-bug-critical ☢ Exception rasing submodule ⊂ Periphery/subclasses to-merge ↰ Imminent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants