-
Notifications
You must be signed in to change notification settings - Fork 20
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
Add NumPy 2 support #605
base: main
Are you sure you want to change the base?
Add NumPy 2 support #605
Conversation
Update: Opened issue numpy/numpy#27679 |
Confirmation this is a bug from NumPy, we'll have to wait until it is fixed there to update to 2.0. Will likely take a while! |
Thanks for looking into this! It's a pity the issue prevents us from upgrading. Some colleagues have had the issue that numpy 2 was installed in there environment and xdem was not working anymore... |
That's annoying indeed... We pinned the max version of NumPy a bit late, so solving for GeoUtils/xDEM in a NumPy 2.0 env will install older versions, that will indeed fail. It might take a very long time to get a fix in NumPy, and it's a small aspect, so we could look for a way to circumvent in the meantime. |
This PR updates GeoUtils to support NumPy 2.0.
I am not going to merge it now, as some issues arising seem to come from potentially undesirable NumPy masked-array behaviour.
Summary
The issue is the new casting rules for scalars with arrays, especially for integers, see here: https://numpy.org/devdocs/numpy_2_0_migration_guide.html#changes-to-numpy-data-type-promotion and https://numpy.org/neps/nep-0050-scalar-promotion.html#nep50 for details.
The above rules make sense, but don't seem to behave the same for masked array. Somehow, we cannot easily cast an integer with a masked array of lower integer-type anymore:
For instance:
runs fine.
But:
yields:
Additionally
With the new scalar casting behaviour, we might have to relax the current behaviour of
Raster.data.setter()
expecting the same data type, otherwise this type of command to simply update the array:might fail a lot.
We can dive into this in more details once the above exception is clarified.
Steps forward
I will open an issue on NumPy's GitHub after triple-checking if this is intended behaviour, but I don't think so.