Skip to content
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

Add support for enumerate #1522

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

vincentblot28
Copy link

Enable the use of "enumerate" as iterable of tqdm. With this feature, tqdm automatically compute the total number of iterations when the argument of tqdm is of type "enumerate"

Comment on lines -979 to +982
total = len(iterable)
if isinstance(iterable, enumerate):
total = len(list(iterable))
else:
total = len(iterable)
Copy link

@niqodea niqodea Oct 18, 2023

Choose a reason for hiding this comment

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

I am not sure this change will be approved. By calling list on the enumerate iterable you are potentially loading an entire dataset into memory, and also consuming the iterable.

Copy link

Choose a reason for hiding this comment

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

You could extract the wrapped iterable and work with that instead.

Copy link

Choose a reason for hiding this comment

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

Anyhow, the standard way to use tqdm together with enumerate is to wrap with tqdm first and enumerate second:

enumerate(tqdm(iterable))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants