tqdm/tqdm

unable to set format for numbers with unit_scale

Opened this issue · 0 comments

Hi,

we've got the following bug report in Debian that I'd like to relay here (https://bugs.debian.org/1069702):

---snip---
I'm having trouble formatting numbers in progress bars when using
unit_scale. Unfortunately, there doesn't seem to be a way to do this
without overriding a lot of code.

As shown in line 565 of /usr/lib/python3/dist-packages/tqdm/std.py, the
str() method is being used to convert the floats to strings before
printing them.

Minimal working example:

import tqdm
import time

for i in tqdm.tqdm(range(7), unit_scale=1/7):
time.sleep(0.1)
print()

Output for this code:

0%| | 0.0/1.0 [00:00<?, ?it/s]
14%|████▍ | 0.14285714285714285/1.0 [00:00<00:00, 1.42it/s]
29%|█████████▏ | 0.2857142857142857/1.0 [00:00<00:00, 1.42it/s]
43%|█████████████▎ | 0.42857142857142855/1.0 [00:00<00:00, 1.42it/s]
57%|██████████████████▎ | 0.5714285714285714/1.0 [00:00<00:00, 1.42it/s]
71%|██████████████████████▊ | 0.7142857142857142/1.0 [00:00<00:00, 1.42it/s]
86%|███████████████████████████▍ | 0.8571428571428571/1.0 [00:00<00:00, 1.42it/s]
100%|███████████████████████████████████████████████| 1.0/1.0 [00:00<00:00, 1.42it/s]
---snap---

Regards,
Daniel