BUG: avoid float upcast when mixing signed/unsigned ints in isin #62608
+24
−4
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.
…ts added)
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.Summary
Fix incorrect Series.isin results when comparing signed int64 values with uint64 values that are not equal. Previously, mixing signed and unsigned 64-bit integers could trigger a numeric common-type coercion to float64 which may lose precision and produce false positives. This change prevents that unsafe upcast by preferring an object-based comparison when signed and unsigned integer types are mixed.
Root cause
When isin attempted to find a common numeric dtype between comps (left side) and values (right side), mixing signed int64 with uint64 could lead to casting both sides to float64. Converting large 64-bit integers to float64 loses precision and can make two distinct integers compare as equal.
What I changed
[algorithms.py]:
Adjusted the condition used before converting values to an object array so that when dtypes differ and either side is an unsigned integer, [values] is converted to object (i.e., Python-level equality / hashtable lookup) instead of numeric coercion. This makes the mixed signed/unsigned decision symmetric and avoids unsafe float upcasts.
[test_isin.py]
Added test_isin_int64_vs_uint64_mismatch which reproduces the reported case and asserts the correct False result.