Skip to content

Commit

Permalink
Use total kwarg as tqdm length if provided
Browse files Browse the repository at this point in the history
  • Loading branch information
fcoclavero committed Jun 14, 2021
1 parent a141b89 commit 6a755c8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions p_tqdm/p_tqdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ def _parallel(ordered: bool, function: Callable, *iterables: Iterable, **kwargs:
elif type(num_cpus) == float:
num_cpus = int(round(num_cpus * cpu_count()))

# Determine length of tqdm (equal to length of shortest iterable)
length = min(len(iterable) for iterable in iterables if isinstance(iterable, Sized))
# Determine length of tqdm (equal to length of shortest iterable or total kwarg)
total = kwargs.pop('total', None)
length = total or min(len(iterable) for iterable in iterables if isinstance(iterable, Sized))

# Create parallel generator
map_type = 'imap' if ordered else 'uimap'
Expand Down

0 comments on commit 6a755c8

Please sign in to comment.