tests: Update pygrass doctests for NumPy 2 compatibility (#4100)#7194
tests: Update pygrass doctests for NumPy 2 compatibility (#4100)#7194Khansa435 wants to merge 5 commits intoOSGeo:mainfrom
Conversation
|
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
|
@echoix @wenzeslaus @ninsbl |
|
Hi @echoix @wenzeslaus @ninsbl |
|
Hi @echoix, Can you please review the changes :) |
|
Can you please take a look at the CI logs and understand why the some tests (including doctests) fail there? |
|
@echoix Running ./python/grass/pygrass/raster/testsuite/test_pygrass_raster_doctests.py.....======================================================================== Initially, there was a failing check for numpy compatibilty issue but that gave details like "Expected: " and "Got: " which I fixed but now this one is not clear as to why these are failing. |
|
You could try to run failing tests locally... |
|
@echoix @ninsbl collected 0 items # Normal for doctest-only files But the CI Summary and artifacts downloads result showed return code -11 (segfault) on dataset maybe. So it looks like my numpy2 doctest fixes are working fine locally. The CI crash seems to be environment/dataset specific rather than a code problem... What do you think? Or am I missing something here? :/ |
|
In your pytest run, how many were marked "passed"? To make sure they work, change the file with the doctest your trying, and deliberately change a number to make it fail. If it doesn't fail, either the file you changed isn't the one actually running, or your method of invoking it doesn't work. But, I'm pretty sure that the doctests aren't collected and running through pytest. They have a different setup I think, that Pytest isn't configured to set it. They are supposed (for now) to be run with gunittest, with the appropriate dataset for it. |

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.