Skip to content

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

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

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

Conversation

@echoix

@echoix echoix commented Oct 4, 2026

Copy link
Copy Markdown
Member

To review: Decide if it makes sense to order these lines, I think it’s right, but just in case I’m missing something.

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 #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.

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.
@github-actions github-actions Bot added Python Related code is in Python libraries module imagery tests Related to Test Suite labels Oct 4, 2026
@echoix
echoix requested a review from ninsbl October 10, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

imagery libraries module Python Related code is in Python tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants