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

initial= parameter seems not working properly #215

Open
DeoLeung opened this issue Jul 27, 2016 · 6 comments
Open

initial= parameter seems not working properly #215

DeoLeung opened this issue Jul 27, 2016 · 6 comments
Assignees
Labels
p2-bug-warning ⚠ Visual output bad question/docs ‽ Documentation clarification candidate to-fix ⌛ In progress
Milestone

Comments

@DeoLeung
Copy link

import tqdm
from time import sleep

to_mongo_pbar = tqdm.trange(100, desc='to Mongo', initial=30)
for i in tqdm.trange(100, desc='imputed', initial=30):
  sleep(0.1)
  # do something else for to_mongo_pbar
  to_mongo_pbar.update(1)
to_mongo_pbar.close()

for this snippet I would expect the iteration(i) start from 30 and finish at 99, however it extend the counter to 129
is it a bug or expected behaviour?

to Mongo: 130it [00:10,  9.83it/s]
@casperdcl
Copy link
Member

casperdcl commented Jul 27, 2016

Hi, initial only sets the initial offset for iteration display (I.e.
it'll start displaying 30/100 in your example, then go on to 130/100.) what
you need is to let (x)range know you want to start at 30 as well.

trange(30, 100, initial=30, ...)

On 27 Jul 2016 2:21 a.m., "Zhanzhao (Deo) Liang" [email protected]
wrote:

import tqdmfrom time import sleep

to_mongo_pbar = tqdm.trange(100, desc='to Mongo', initial=30)for i in tqdm.trange(100, desc='imputed', initial=30):
sleep(0.1)

do something else for to_mongo_pbar

to_mongo_pbar.update(1)
to_mongo_pbar.close()

for this snippet I would expect the iteration(i) start from 30 and finish
at 99, however it extend the counter to 129
is it a bug or expected behaviour?

to Mongo: 130it [00:10, 9.83it/s]

@DeoLeung
Copy link
Author

@casperdcl

import tqdm
from time import sleep

to_mongo_pbar = tqdm.trange(30, 100, desc='to Mongo', initial=30)
for i in tqdm.trange(30, 100, desc='imputed', initial=30):
  sleep(0.1)
  # do something else for to_mongo_pbar
  to_mongo_pbar.update(1)
to_mongo_pbar.close()

this is still failing, it starts at 30/70, continue to exeeds the remain 30 it , which I think it should be 30/100

to Mongo: 100it [00:07,  9.63it/s]

@casperdcl
Copy link
Member

casperdcl commented Jul 30, 2016

ah sorry, the length of your iterable is 70, so you don't need initial.

for x in tqdm.trange(30, 100):
   ...
# or
for x in tqdm.tqdm(range(30, 100)):
  ...

the displayed bar would go from 0/70 to 70/70. I think currently the only way to start at 30/100 and go to 100/100 (if that's what you really really really want) is:

r = range(100)[30:]
for x in tqdm.tqdm(r, initial=30):
  ...

either way, I've assumed you want x to start at 30 and finish at 99.

@lrq3000
Copy link
Member

lrq3000 commented Aug 1, 2016

He can also set the total manually, that's what I did (I often used initial to get back from a pause between two sections of code):

import time
from tqdm import trange

upper_bound=100
current=30
for x in trange(current, upper_bound, total=upper_bound, initial=current):
    time.sleep(0.1)

@lrq3000 lrq3000 added the question/docs ‽ Documentation clarification candidate label Aug 1, 2016
@lrq3000
Copy link
Member

lrq3000 commented Aug 7, 2016

Please feel free to report if this solved your issue, or open it again if not!

@lrq3000 lrq3000 closed this as completed Aug 7, 2016
@yashetty29
Copy link

The range works perfectly the problem the iteration speed the iteration speed at the end counts from 0-100 instead of just from 30-100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-bug-warning ⚠ Visual output bad question/docs ‽ Documentation clarification candidate to-fix ⌛ In progress
Projects
None yet
Development

No branches or pull requests

4 participants