-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle larger than 32bit distances when creating Hilbert distance and spatially partitioning. #219
base: main
Are you sure you want to change the base?
Conversation
set hilbert distance to dtype to int64
add test
fix formatting
fix formatting
fix formatting
fix formatting
Looks like the failures are not related to my changes. |
@@ -389,7 +389,7 @@ def hilbert_distance(self, total_bounds=None, level=16): | |||
_hilbert_distance, | |||
total_bounds=total_bounds, | |||
level=level, | |||
meta=pd.Series([], name="hilbert_distance", dtype="uint32"), | |||
meta=pd.Series([], name="hilbert_distance", dtype=np.int64), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be an option provided by the user, rather than assuming int64. The default should be uint32 for backwards compatability.
@@ -43,7 +43,9 @@ def _hilbert_distance(gdf, total_bounds=None, level=16): | |||
# Compute distance along hilbert curve | |||
distances = _encode(level, x, y) | |||
|
|||
return pd.Series(distances, index=gdf.index, name="hilbert_distance") | |||
return pd.Series( | |||
distances, index=gdf.index, name="hilbert_distance", dtype=np.int64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't distances
already be a uint32
? I suspect that the changes will need to be at a lower level (maybe in _encode
), and then when we're constructing a Series here the dtype will just be the dtype of whatever ndarray is passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you are right, i had missed that this is actually an unsigned int. The reason for the overflow is actually that the value is greater than the max value for int but not uint, and dask simply isn't respecting the dtype.
FYI this problem seems to be only an issue with dask<2022.8 and pandas<1.5 |
In this case I suggest we recommend people updating their environment and close this PR. |
d1a6bcd
to
f8da2f6
Compare
I have come across an issue with spatially partitioning data where the distance between geometry as calculated by hilbert_distance is greater than a 32bit integer. The meta for the returned series is set to 32bit which causes dask to cast down to 32bit when setting index, this causes an overflow and the resulting divisions being out of order. Here is a minimal example to show the issue.
setting correctly to int64 before passing to dask fixes this issue.
It should be a simple fix to handle these cases, so I've gone ahead and created a branch for your review.