Skip to content

tqdm by default rounds up and reports 100% before actually finishing #1398

@mlubej

Description

@mlubej

If there are enough steps in the loop so that the increment is small enough, it can happen that tqdm shows 100% even though the process hasn't finished yet. This is the default behavior and I think it should be changed to stop at 99% before actually finishing.

MVE:

from time import sleep
from tqdm.cli import tqdm

n = 1000
for idx in tqdm(range(n)):
    if idx == n-1:
        break
    sleep(1/n)

image

I know it's possible to change the bar format to show decimals, e.g.

from time import sleep
from tqdm.cli import tqdm

n = 1000
for idx in tqdm(range(n), bar_format = "{desc}: {percentage:.1f}%|{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}]"):
    if idx == n-1:
        break
    sleep(1/n)

image

but this probably isn't an acceptable solution for everyone.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions