Skip to content

tests: Update pygrass doctests for NumPy 2 compatibility (#4100)#7194

Open
Khansa435 wants to merge 3 commits intoOSGeo:mainfrom
Khansa435:fix-numpy2-doctests
Open

tests: Update pygrass doctests for NumPy 2 compatibility (#4100)#7194
Khansa435 wants to merge 3 commits intoOSGeo:mainfrom
Khansa435:fix-numpy2-doctests

Conversation

@Khansa435
Copy link

Description

Fixes #4100
(and also addresses the underlying cause behind #4116 )

This PR updates the gunittest doctest 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 of 1, 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 main is 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

  • Bumped CI requirements: Updated numpy to numpy>=2.0.0 in .github/workflows/python_requirements.txt to guarantee the test environments use NumPy 2.
  • Un-excluded raster doctests: Re-enabled python/grass/pygrass/raster/testsuite/test_pygrass_raster_doctests.py in .gunittest.cfg so the test suite will run these tests again.
  • Updated scalar representations: Fixed the expected output in python/grass/pygrass/utils.py (get_raster_for_points) to expect the explicit np.int32(1) NumPy 2 scalar wrapper.
  • Updated array representations: Removed the 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.
@github-actions github-actions bot added CI Continuous integration Python Related code is in Python libraries tests Related to Test Suite labels Mar 18, 2026
@Khansa435 Khansa435 changed the title test: Update pygrass doctests for NumPy 2 compatibility (#4100) tests: Update pygrass doctests for NumPy 2 compatibility (#4100) Mar 18, 2026
@Khansa435
Copy link
Author

Khansa435 commented Mar 19, 2026

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? :)

@Khansa435 Khansa435 force-pushed the fix-numpy2-doctests branch from b706b30 to 829c621 Compare March 19, 2026 14:43
@Khansa435
Copy link
Author

Khansa435 commented Mar 19, 2026

@echoix @wenzeslaus @ninsbl
Can you please take a look and review the changes I made :)

@Khansa435
Copy link
Author

Hi @echoix @wenzeslaus @ninsbl
Just a polite followup on requesting for the review of my code changes please :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Continuous integration libraries Python Related code is in Python tests Related to Test Suite

1 participant