tests: Update pygrass doctests for NumPy 2 compatibility (#4100)#7194
Open
Khansa435 wants to merge 3 commits intoOSGeo:mainfrom
Open
tests: Update pygrass doctests for NumPy 2 compatibility (#4100)#7194Khansa435 wants to merge 3 commits intoOSGeo:mainfrom
Khansa435 wants to merge 3 commits intoOSGeo:mainfrom
Conversation
Author
| Hi @echoix @wenzeslaus ! I've updated this PR with a fix for NumPy 2.x compatibility using # doctest: +ELLIPSIS wildcards. This approach supports both NumPy 2 and the older NumPy 1.x used in the Ubuntu CI. Could you please approve the workflows to run as they require approval from a maintainer? :) |
b706b30 to 829c621 Compare Author
| @echoix @wenzeslaus @ninsbl |
Author
| Hi @echoix @wenzeslaus @ninsbl |
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.
Description
Fixes #4100
(and also addresses the underlying cause behind #4116 )
This PR updates the
gunittestdoctest suite to be fully compatible with NumPy 2.0+.NumPy 2.0 introduced changes to the string representation of arrays and scalar types (e.g., scalars now print as
np.int32(1)instead of1, and arrays with non-default dtypes are formatted differently depending on the default platform size). This caused several doctests to fail, leading to test_pygrass_raster_doctests.py being excluded from the test suite.As discussed with @echoix in the issue thread, since
mainis moving towards the 8.6 release, the strategy here is to explicitly target the NumPy 2 string representations natively rather than retaining backward compatibility with NumPy 1.x string outputs.Changes Made
numpy>=2.0.0in .github/workflows/python_requirements.txt to guarantee the test environments use NumPy 2.np.int32(1)NumPy 2 scalar wrapper.dtype=parameter from expected Buffer outputs in python/grass/pygrass/raster/init.py. In NumPy 2 on standard configurations, these standard buffer arrays omit the dtype parameter string during formatting.