Repository navigation
Conversation
Collaborator
|
Hi @aalquwayfili thanks for the contribution and apologies for the delayed response. The bug seems real, the impact seems small but I don't see no reason to fix it. Could you please target the changes to the narwhals-migration branch? thank you! |
aalquwayfili
force-pushed
the
fix-geodistance-integer-overflow
branch
from
November 29, 2026 08:50
0d3786b to
0300171
Compare
Author
|
Thanks! Moved it to narwhals-migration. The overflow is still there on both pandas and polars, so I made the test run on both. |
Converting the coordinates to float64 in transform fixes the overflow for all methods, and haversine no longer computes in float16 or float32 with small integer dtypes. The range checks compare against both bounds, since np.abs overflows on the minimum of signed integer dtypes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
solegalli
merged commit Nov 29, 2026
10dc8f4
into
feature-engine:narwhals-migration
3 of 9 checks passed
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.
GeoDistanceFeaturesgives wrong distances when the coordinates are small int dtypes:uint8points(1, 2)and(0, 1)give about 40,029 km instead of 157 km.int8anduint8coordinates, and in float32 withint16, so it returns a Float16 or Float32 column and loses precision. For example, New York to Los Angeles gives 3,920.0 km instead of 3,923.6 km withint8coordinates.np.absoverflows there. For example, anint8latitude of -128 passes.Now
transformconverts the coordinates to float64 once, so all three methods compute and return float64, and the range checks compare against both bounds instead of usingnp.abs. Results on float64 coordinates don't change.Added tests on pandas and polars for the overflow, for integer coordinates giving the same distances as float coordinates with every method, and for the range checks at the integer minimum.