You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromp_tqdmimportp_uimapdefincrement(x):
returnx+1it= (iforiinrange(5)) # don't use range directly, because it is Sizedforxinp_uimap(f, it):
print(x)
the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/cthoyt/.virtualenvs/integrator/lib/python3.8/site-packages/p_tqdm/p_tqdm.py", line 42, in _parallel
length =min(len(iterable) for iterable in iterables ifisinstance(iterable, Sized))
ValueError: min() arg is an empty sequence
This happens because there are no sized iterables, and it's trying to take the min() of an empty sequence. This could be solved a few ways:
Surrounding this line with try/except, then setting length=None. This is an optional argument to tqdm() so this is okay, but will not longer be able to give an estimate
try:
# Determine length of tqdm (equal to length of shortest iterable)length=min(len(iterable) foriterableiniterablesifisinstance(iterable, Sized))
exceptValueError:
length=None
Save the list of iterables (this won't be so long) that are sized and check it explicitly for not being empty. If it is, set length=None
# Determine length of tqdm (equal to length of shortest iterable), if possiblelengths= [len(iterable) foriterableiniterablesifisinstance(iterable, Sized)]
length=min(lengths) iflengthselseNone
I'm not sure which you would prefer, but they effectively accomplish the same thing. I made a PR #28 that uses the second solution.
The text was updated successfully, but these errors were encountered:
cthoyt
added a commit
to cthoyt/p_tqdm
that referenced
this issue
Sep 16, 2020
The following code throws a
ValueError
:the error:
This happens because there are no sized iterables, and it's trying to take the min() of an empty sequence. This could be solved a few ways:
length=None
. This is an optional argument totqdm()
so this is okay, but will not longer be able to give an estimatelength=None
I'm not sure which you would prefer, but they effectively accomplish the same thing. I made a PR #28 that uses the second solution.
The text was updated successfully, but these errors were encountered: