Repository navigation
Conversation
Use exact mixed comparison loops when floating-point promotion would lose integer precision. Closes numpy#32071.
abdulm5
marked this pull request as ready for review
July 30, 2026 23:16
Member
|
Just a head’s up that I did a very brief history skim to come to the conclusion that this is worth doing. There are very real backward compatibility concerns someone will need to sort through before we can review this. I’d like you to go through history and figure out why this was excluded from the NumPy 1.25 change that fixed #12525 . Should we generate deprecation warnings? How do we do that performantly and without noisily generating unnecessary warnings? |
ngoldbaum
marked this pull request as draft
July 31, 2026 14:11
Member
|
I marked this as draft to indicates that we still need design work before merging a change like this. |
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.
PR summary
Closes #32071.
Comparisons between NumPy integers and real floating-point values currently
use common-dtype promotion. When the floating-point dtype cannot represent
every value of the integer dtype, that promotion can round the integer before
the comparison. For example,
np.int64(2**53 + 1)can compare equal tonp.float64(2**53), even though the two scalars have different hashes.This PR:
against double and long-double values, in both operand orders and for all six
comparison operations;
rich comparisons through those loops when the integer precision exceeds the
floating-point mantissa;
infinities, both operand orders, scalar and array calls, and the
equality/hash invariant; and
on lossy mixed integer/floating-point comparison.
After this change:
Validation performed locally:
spin build --clean -j 4spin test --no-build -- -q: 47,470 passedspin test -m full --no-build -- -q: 50,812 passed; the only remainingcase was denied POSIX shared-memory access by the sandbox and passed when
rerun outside the sandbox
spin lintgit diff --checksemantics
First time committer introduction
Hi, this is my first contribution to NumPy. I worked on #32071 to make mixed
integer/floating-point comparisons follow Python's exact comparison semantics
and preserve the equality/hash contract.
AI Disclosure
OpenAI Codex was used to investigate the comparison dispatch paths, generate
the C, C++, and Python implementation changes, add and adapt tests, and run
local validation. I reviewed all generated and AI-assisted changes, understand
the implementation and tests, and take responsibility for this contribution.