Skip to content

i.oif: Sort NaN results last and fix pygrass doctest for numpy 2 - #726

Open
echoix wants to merge 1 commit into
mainfrom
fix-numpy2-oif-nan
Open

echoix wants to merge 1 commit into
mainfrom
fix-numpy2-oif-nan

Conversation

@echoix

@echoix echoix commented Oct 3, 2026 •

Copy link
Copy Markdown
Owner

Description

  • grass.pygrass.utils.get_raster_for_points doctest: the expected output uses ...1..., which the existing +ELLIPSIS directive matches with both numpy 1 and numpy 2.
  • i.oif: NaN results are sorted last, in input order, and test_constant_raster_yields_nan expects that order. This changes the output order of i.oif when an input band has zero variance.

Motivation and context

With numpy 2, the doctest prints np.int32(1) instead of 1. Sorting (oif, bands) tuples that contain NaN has no well-defined order, so the i.oif output order depended on the sort algorithm.

These are the failures seen in OSGeo#4372, so this change improves the situation there, even though adding Python 3.13 support is not the goal of this PR.

How has this been tested?

The Ubuntu and macOS gunittest jobs run test_pygrass_doctests.py and test_i_oif.py and pass. Both use numpy 1.26.4. The Windows (OSGeo4W) job uses numpy 2.4.6: the get_raster_for_points examples pass there, and only the final remove() cleanup example fails on a Windows file-locking error.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing
    functionality to not work as before)

Checklist

  • PR title provides summary of the changes and starts with one of the
    pre-defined prefixes
  • My code follows the code style
    of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

Written with the help of Claude Code.

@echoix
echoix force-pushed the fix-numpy2-oif-nan branch from 017e3e1 to b31cfc6 Compare October 3, 2026 23:40
@echoix echoix changed the title CI: Fix doctest and i.oif NaN ordering failures with numpy 2 i.oif: Sort NaN results last and fix pygrass doctest for numpy 2 Oct 3, 2026
@echoix
echoix force-pushed the fix-numpy2-oif-nan branch 2 times, most recently from 4d4cf38 to 3fa227a Compare October 4, 2026 17:33
Sorting (oif, bands) tuples that contain NaN has no well-defined order,
so the output order of i.oif depended on the sort algorithm. Place NaN
results last, in input order, and update the test to expect that.

The get_raster_for_points doctest in grass.pygrass.utils expected `1`,
but numpy 2 prints `np.int32(1)`. Match it with the ellipsis directive
already present.

Both showed up when running the full Ubuntu test configuration with the
latest Python and numpy.

Written with the help of Claude Code.
@echoix
echoix force-pushed the fix-numpy2-oif-nan branch from 3fa227a to b633adc Compare October 4, 2026 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants