Skip to content

Commit

Permalink
Merge pull request #35 from fcoclavero/feature/total-kwarg
Browse files Browse the repository at this point in the history
Use the total kwarg as the tqdm length if provided.
  • Loading branch information
swansonk14 authored Apr 19, 2022
2 parents edd6325 + 6a755c8 commit f7414a9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ p_tqdm.egg-info
__pycache__
*.pyc
.idea
venv
.venv
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 f7414a9

Please sign in to comment.