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

Fix unit_scale rate #608

Merged
merged 11 commits into from
Oct 15, 2018
Merged

Fix unit_scale rate #608

merged 11 commits into from
Oct 15, 2018

Conversation

chengs
Copy link
Contributor

@chengs chengs commented Sep 11, 2018

fix #449

tqdm/tqdm/_tqdm.py

Lines 893 to 899 in e32428c

return self.format_meter(
self.n, self.total, self._time() - self.start_t,
self.dynamic_ncols(self.fp)
if self.dynamic_ncols else self.ncols, self.desc, self.ascii,
self.unit, self.unit_scale,
1 / self.avg_time if self.avg_time else None,
self.bar_format, self.postfix)

by default, in format_meter, the parameter rate is set to be 1/self.avg_time.
This self.avg_time is the average time of ONE iteration. So if unit_scale>1, this rate should also be scaled, which will fix #449.

Test:

# with unit_scale [WRONG]
for i in tqdm(range(100), unit_scale=10, ncols=100):
    time.sleep(.1)

Without this PR, the remaining time is wrong.
With this PR, it is correct.

Thanks to the analysis by @adrtod.

@codecov-io
Copy link

codecov-io commented Sep 11, 2018

Codecov Report

Merging #608 into master will decrease coverage by 0.26%.
The diff coverage is 75%.

@@            Coverage Diff            @@
##           master    #608      +/-   ##
=========================================
- Coverage   98.87%   98.6%   -0.27%     
=========================================
  Files           9      10       +1     
  Lines         709     717       +8     
  Branches      127     128       +1     
=========================================
+ Hits          701     707       +6     
- Misses          5       6       +1     
- Partials        3       4       +1

@casperdcl casperdcl self-assigned this Sep 11, 2018
@casperdcl casperdcl added the to-review 🔍 Awaiting final confirmation label Sep 11, 2018
@casperdcl casperdcl changed the title fix #449 Fix unit_scale rate Sep 11, 2018
@casperdcl casperdcl added to-merge ↰ Imminent and removed to-review 🔍 Awaiting final confirmation labels Oct 14, 2018
@casperdcl casperdcl merged commit 548ee7d into tqdm:master Oct 15, 2018
casperdcl added a commit that referenced this pull request Oct 15, 2018
- fix `str.isnumeric` #605
- fix `WeakSet` `KeyError` #548, #553, #596 -> #607
- stop `tqdm_notebook` description truncation #582 -> #599
- include `unit_scale` for `rate` #608
- add `auto` -> nowarning `autonotebook`
- add better postfix numeric formatting #621
- minor refactoring #609 -> #616
- update documentation
- add unit tests
- fix py26 CI
casperdcl added a commit that referenced this pull request Oct 15, 2018
- fix `str.isnumeric` #605
- fix `WeakSet` `KeyError` #548, #553, #596 -> #607
- stop `tqdm_notebook` description truncation #582 -> #599
- include `unit_scale` for `rate` #608
- add `auto` -> nowarning `autonotebook`
- add better postfix numeric formatting #621
- minor refactoring #609 -> #616
- update documentation
- add unit tests
- fix py26 CI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong remaining time when using unit_scale and smoothing
4 participants