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

Estimated completion date/time in bar_format #1055

Merged
merged 4 commits into from
Oct 24, 2020

Conversation

kolayne
Copy link
Contributor

@kolayne kolayne commented Oct 22, 2020

Closes #1051

Adds the possibility to display ETA date and time. Example of basic usage of the feature:

from time import sleep
from random import randint

from tqdm import trange


for i in trange(20, bar_format='{l_bar}{bar}{r_bar} ({eta_dt})'):
    sleep(randint(1, 5) / 10)
How this looks

2020-10-22 13-16-31

You can also customize the date format with the directives from the datetime library (see the official documentation):

from time import sleep
from random import randint

from tqdm import trange


for i in trange(20, bar_format='{l_bar}{bar}{r_bar} ({eta_dt:%Y.%m.%d, %H:%M})'):
    sleep(randint(1, 5) / 10)
How this looks

2020-10-22 13-20-48

Notes

  • Works for Python 2 just in the same way (in the samples above you should wrap randint in float, but no changes to tqdm calls are needed)
  • When it's impossible to calculate ETA (i. e. first iteration or no total and length of an iterable is unavailable), eta_dt defaults to the epoch beginning datetime (to not break formatting directives usage)

@kolayne kolayne force-pushed the estimated_completion_datetime branch from f3a2d6d to fe75e0a Compare October 22, 2020 10:25
@codecov-io
Copy link

codecov-io commented Oct 22, 2020

Codecov Report

Merging #1055 into devel will increase coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##            devel    #1055      +/-   ##
==========================================
+ Coverage   86.40%   86.44%   +0.04%     
==========================================
  Files          22       22              
  Lines        1456     1461       +5     
  Branches      247      247              
==========================================
+ Hits         1258     1263       +5     
  Misses        167      167              
  Partials       31       31              

@kolayne kolayne force-pushed the estimated_completion_datetime branch from fe75e0a to 396262c Compare October 22, 2020 10:42
@casperdcl
Copy link
Sponsor Member

Exactly the implementation I was thinking of; thanks

@casperdcl casperdcl self-assigned this Oct 22, 2020
@casperdcl casperdcl added this to the Non-breaking milestone Oct 22, 2020
@casperdcl casperdcl added c1-quick 🕐 Complexity low p3-enhancement 🔥 Much new such feature question/docs ‽ Documentation clarification candidate to-merge ↰ Imminent labels Oct 22, 2020
@kolayne kolayne marked this pull request as ready for review October 22, 2020 11:04
@casperdcl casperdcl force-pushed the estimated_completion_datetime branch 2 times, most recently from 415c933 to 9cd652c Compare October 22, 2020 12:13
@casperdcl
Copy link
Sponsor Member

casperdcl commented Oct 22, 2020

made a few changes

  • eta_dt => eta
  • catch OverflowError => max

Example:

tqdm(..., bar_format='{l_bar}{bar}| {n_fmt}/{total_fmt} [{rate_fmt} ETA:{eta:%y-%m-%d %H:%M}{postfix}]')

@casperdcl
Copy link
Sponsor Member

would likely merge #1052 first before adding a test

@casperdcl casperdcl force-pushed the estimated_completion_datetime branch from 9cd652c to 6f90e77 Compare October 22, 2020 12:24
@casperdcl casperdcl changed the base branch from master to devel October 24, 2020 23:11
@casperdcl casperdcl force-pushed the estimated_completion_datetime branch from 6f90e77 to 5ae54a3 Compare October 24, 2020 23:21
@casperdcl casperdcl force-pushed the estimated_completion_datetime branch from 5ae54a3 to 873e1bc Compare October 24, 2020 23:30
@casperdcl casperdcl mentioned this pull request Oct 24, 2020
@casperdcl casperdcl merged commit 07cde64 into tqdm:devel Oct 24, 2020
@kolayne kolayne deleted the estimated_completion_datetime branch October 25, 2020 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c1-quick 🕐 Complexity low p3-enhancement 🔥 Much new such feature question/docs ‽ Documentation clarification candidate to-merge ↰ Imminent
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Estimated Completion Time/Date for Long-Running Processes
3 participants