Clamp precision to non-negative for compatibility with Julia 1.14 - #50
Merged
KristofferC merged 1 commit intoAug 31, 2026
Merged
Conversation
plain_precision_heuristic returns a negative precision when all values
are whole numbers with trailing zeros (e.g. [1000.0, 2000.0]). From
Julia 1.14, Base.Ryu.writefixed throws
ArgumentError("precision must be non-negative") instead of silently
truncating, which breaks showoff (and the many plotting packages
depending on it) on such inputs.
Clamp the heuristic result (and the precision passed to writefixed) to
zero. For the inputs that previously produced a negative precision the
output is unchanged, since those values have no fractional digits.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #50 +/- ##
=======================================
Coverage 84.65% 84.65%
=======================================
Files 2 2
Lines 189 189
=======================================
Hits 160 160
Misses 29 29 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
Author
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.
From Julia 1.14,
Base.Ryu.writefixedthrowsArgumentError("precision must be non-negative")instead of silently truncating on a negative precision.See for example this PkgEval log: https://pkgeval.s3.us-east-2.amazonaws.com/runs/gh-5428371050/logs/primary/MuladdMacro.log
plain_precision_heuristicreturns a negative precision whenever all input values are whole numbers with trailing zeros, so e.g.errors on Julia 1.14, which breaks a large number of downstream plotting packages that use Showoff for tick label formatting.
This PR clamps the heuristic result (and, defensively, the precision passed to
Ryu.writefixedinformat_fixed) to zero. Output is unchanged on older Julia versions for inputs that previously produced a negative precision, since those values have no fractional digits (writefixed(x, -3)andwritefixed(x, 0)agree for whole numbers). Adds regression tests and bumps the version to 1.1.1.