Skip to content

Fix scientific() sign and naturaldelta() negative durations - #268

Closed
Pitchfork-and-Torch wants to merge 1 commit into
jmoiron:masterfrom
Pitchfork-and-Torch:cook/scientific-sign-and-naturaldelta-abs
Closed

Pitchfork-and-Torch wants to merge 1 commit into
jmoiron:masterfrom
Pitchfork-and-Torch:cook/scientific-sign-and-naturaldelta-abs

Conversation

@Pitchfork-and-Torch

Copy link
Copy Markdown

Summary

  • scientific(-1000) incorrectly became 1.00 x 10⁻³ (sign applied to the exponent; -0.001 produced a double-minus). Sign now stays on the coefficient; non-finite values are returned unchanged.
  • naturaldelta(-5) returned "a day" because timedelta(seconds=-5) normalizes to (days=-1, seconds=86395) and the code took abs(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_nonfinite
  • pytest tests/test_time.py::test_naturaldelta_negative_duration

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.
@hugovk

hugovk commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

Wrong repo, but probably a duplicate.

@hugovk hugovk closed this Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants