Repository navigation
Fix scientific() sign and naturaldelta() negative durations - #268
Closed
Pitchfork-and-Torch wants to merge 1 commit into
Closed
Pitchfork-and-Torch wants to merge 1 commit into
Pitchfork-and-Torch wants to merge 1 commit into
Conversation
scientific() was stripping "-" from the mantissa and applying it to the exponent instead, so scientific(-1000) became "1.00 x 10⁻³" (and scientific(-0.001) produced a double-minus exponent). Put the sign on the coefficient and return non-finite values unchanged. naturaldelta() used abs(delta.days) and abs(delta.seconds) separately. Python normalizes timedelta(seconds=-5) to (days=-1, seconds=86395), so negative short durations were reported as "a day". Normalize via negation before reading components.
Collaborator
|
Wrong repo, but probably a duplicate. |
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.
Summary
scientific(-1000)incorrectly became1.00 x 10⁻³(sign applied to the exponent;-0.001produced a double-minus). Sign now stays on the coefficient; non-finite values are returned unchanged.naturaldelta(-5)returned"a day"becausetimedelta(seconds=-5)normalizes to(days=-1, seconds=86395)and the code tookabs(days)/abs(seconds)separately. Negative durations are normalized before reading components.Test plan
pytest tests/test_number.py::test_scientific tests/test_number.py::test_scientific_negative_and_nonfinitepytest tests/test_time.py::test_naturaldelta_negative_duration