Skip to content
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

Ensure compatibility with numpy 2.0 #396

Closed
phargogh opened this issue Jun 18, 2024 · 0 comments · Fixed by #397
Closed

Ensure compatibility with numpy 2.0 #396

phargogh opened this issue Jun 18, 2024 · 0 comments · Fixed by #397
Assignees
Labels
bug Something isn't working in progress Working on it!

Comments

@phargogh
Copy link
Member

Numpy 2.0 was just released, and when I install the latest version (numpy=2.0.0) into an environment and run python -m pytest tests, I'm getting a few failures on my mac:

FAILED tests/test_geoprocessing.py::TestGeoprocessing::test_raster_map_nodata - TypeError: can_cast() does not support Python ints, floats, and complex because the result used to depend on the value.
FAILED tests/test_geoprocessing.py::TestGeoprocessing::test_raster_map_nodata_and_dtype - TypeError: can_cast() does not support Python ints, floats, and complex because the result used to depend on the value.
FAILED tests/test_geoprocessing.py::TestGeoprocessing::test_raster_map_nodata_propagates - TypeError: can_cast() does not support Python ints, floats, and complex because the result used to depend on the value.
FAILED tests/test_geoprocessing.py::TestGeoprocessing::test_reclassify_raster_reclass_max_nodata - TypeError: in method 'Band_SetNoDataValue', argument 2 of type 'double'

Since this is a major api change, maybe we should expand our test matrix to test against numpy 2.0 if we aren't already?

@phargogh phargogh added the bug Something isn't working label Jun 18, 2024
@phargogh phargogh self-assigned this Jun 18, 2024
@phargogh phargogh added the in progress Working on it! label Jun 18, 2024
phargogh added a commit to phargogh/pygeoprocessing that referenced this issue Jun 18, 2024
Builds were failing without this line.
RE:natcap#396
phargogh added a commit to phargogh/pygeoprocessing that referenced this issue Jun 18, 2024
Numpy 2.0 changed the behavior of numpy.can_cast(): can_cast() was
looking at the type of the int, not the value, I guess.  Updating to use
numpy.result_type definitely uses the scalar value.

RE:natcap#396
phargogh added a commit to phargogh/pygeoprocessing that referenced this issue Jun 18, 2024
This approach is better - numpy has a function for checking the minimum
dtype needed for a scalar value, so we can use that to see if the type
can cast correctly. RE:natcap#396
phargogh added a commit to phargogh/pygeoprocessing that referenced this issue Jun 18, 2024
GDAL only wants python ints/floats, not numpy ints/floats. RE:natcap#396
phargogh added a commit to phargogh/pygeoprocessing that referenced this issue Jun 18, 2024
phargogh added a commit to phargogh/pygeoprocessing that referenced this issue Jun 18, 2024
phargogh added a commit to phargogh/pygeoprocessing that referenced this issue Jun 19, 2024
phargogh added a commit to phargogh/pygeoprocessing that referenced this issue Jun 19, 2024
phargogh added a commit to phargogh/pygeoprocessing that referenced this issue Jun 20, 2024
phargogh added a commit to phargogh/pygeoprocessing that referenced this issue Jun 20, 2024
phargogh added a commit to phargogh/pygeoprocessing that referenced this issue Jun 24, 2024
phargogh added a commit to phargogh/pygeoprocessing that referenced this issue Jun 24, 2024
phargogh added a commit to phargogh/pygeoprocessing that referenced this issue Jun 27, 2024
phargogh added a commit to phargogh/pygeoprocessing that referenced this issue Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working in progress Working on it!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant