-
Notifications
You must be signed in to change notification settings - Fork 259
[style] Improve integer completion percentage calculation for accurate representation (358/359 is NOT 100%) #705
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
base: main
Are you sure you want to change the base?
Conversation
By default rust float formatting doesn't round down - in fact they use round_ties_even udner the hood: https://doc.rust-lang.org/std/primitive.f32.html#method.round_ties_even For percentage calculations this is not great - in particular we shouldn't show 100% when the operation is not fully complete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't find .floor()
an improvement over the current behavior -- now 1/359 is going to be 0% which seems about equally bad. Suggest you use percent_precise
instead or implement ProgressTracker
to implement custom behavior.
I don't think it's equally bad: 1/359 means that the work is not 1% complete yet. 0% seems correct. I believe rounding down consistently is an improvement and de-facto industry standard. Almost every progress reporting logic I've seen before was using integer division for computing percentage - which made rounding down the default behaviour. |
I'm still not convinced. For all past indicatif users, this hasn't been enough of a problem to remark upon. IMO conceptually rounding is the least surprising behavior. |
Is this proposal logically incorrect though? I've never seen a progress indicator say 100% complete when there is work still on the table. Showing "100% (358/359)" is a bad UX bug at best and will more likely waste lots of time debugging. |
As an alternative solution, you can use |
@edward-shen Showing 100% on incomplete progress is confusing and bad ux. |
Just to chime in: I don't have very strong opinions on this. As a user, my main concerns is whether a task is running or has finished. While a task is running, the progress bar provides me with some indication to when the task will be finished. Following that logic, I see the argument to not display "100%" when the task has in fact not finished. Interestingly, from tqdm import tqdm
pbar = tqdm(total=359)
pbar.update(358) emits:
I guess this rarely matters in practise, since there need to be more than 200 steps and the underlying task must be slow enough that users can actually observe the described behaviour. I'm fine with merging this PR, since I don't see any real downside to it. I guess we could even remove these tests, to not "guarantee" any behaviour. |
While I don't have a strong opinion, I think I'd prefer using (aside: I also wonder if I should just create an |
Suggest first making a list in an issue so we can review the evidence of how often different things come up. |
Absolutely, will do. I have plenty of things to do before I go creating another crate (like my neglected work on |
I could live with that if you think it's valuable. |
By default rust float formatting doesn't round down - in fact it uses
round_ties_even
under the hood.For percentage calculations this is not great - in particular we shouldn't show 100% when the operation is not fully complete.