Repository navigation
Fix metric() with precision=0 on very large and very small numbers - #544
Open
LemonCondor wants to merge 1 commit into
Open
LemonCondor wants to merge 1 commit into
LemonCondor wants to merge 1 commit into
Conversation
metric() falls back to scientific() outside of the SI prefix range and passes it precision - 1. With precision=0 this is -1, which scientific() turns into an invalid format specifier, so metric(1e50, precision=0) raised ValueError while metric(1500, precision=0) returned '2 k'. Keep the precision of the fallback at 0 or more. Signed-off-by: Guillaume Marty <[email protected]>
Automation signalsActivity patterns show signs of automation. Evidence
Last 5 PRs: This is an automated analysis by AgentScan |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
metric()switches toscientific()for values outside of the SI prefix range (exponent of 33 or more, or below -30) and passes itprecision - 1. Withprecision=0this is-1, whichscientific()turns into an invalid format specifier:precision=0is accepted elsewhere inmetric()(the number of decimals is clamped withmax(0, ...)) and is covered by the tests, so the fallback now clamps the precision it gives toscientific()the same way:max(precision - 1, 0). The result forprecision=1is unchanged.Two cases are added to
test_metric(1e50and1e-50withprecision=0). They fail before the change with theValueErrorabove, andtests/test_number.pypasses after it (243 tests). I ran it with pytest, not through tox.