Round half-way values towards positive infinity in ROUND - #81
Open
MathiasVDA wants to merge 1 commit into
Open
MathiasVDA wants to merge 1 commit into
MathiasVDA wants to merge 1 commit into
Conversation
SPARQL 1.1 17.4.4.2 (fn:numeric-round): of two equally close integers, the one closest to positive infinity is returned, so round(-2.5) = -2. Polars only offers half-away-from-zero, so negative ties are moved one step up. Refs DataTreehouse#78. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
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.
Requested by Mathias
Fixes #78.
Before:
ROUNDrounded negative half-way values away from zero, soROUND(-2.5)returned -3 andROUND(-0.5)returned -1.After: ties go towards positive infinity, as SPARQL 1.1 §17.4.4.2 requires:
ROUND(-2.5)= -2,ROUND(-0.5)= 0,ROUND(2.5)= 3. Non-tie values and integers are unchanged.How: Polars only offers
HalfToEvenandHalfAwayFromZero. The newsparql_roundhelper rounds half away from zero, then moves negative ties one step up. A value is a negative tie exactly whenx - round(x) == 0.5; that subtraction is exact for ties, also for floats. Integer types are passed through. The helper is used for both single-typed and multi-typed columns. I also removed an unconditionalwith_column(round(...))at the top ofround_, which every branch below overwrote anyway.Tests:
py_maplib/tests/test_round.py(13 cases: decimal, double and integer literals, plus values read from a graph).🤖 Generated with Claude Code