Skip to content

contours: handle infinite nan coords#2749

Merged
brendancol merged 3 commits into
xarray-contrib:mainfrom
Melissari1997:fix/2704-contours-infinite-nan-coords
Jun 1, 2026
Merged

contours: handle infinite nan coords#2749
brendancol merged 3 commits into
xarray-contrib:mainfrom
Melissari1997:fix/2704-contours-infinite-nan-coords

Conversation

@Melissari1997
Copy link
Copy Markdown
Contributor

@Melissari1997 Melissari1997 commented May 31, 2026

Summary

Closes #2704
This PR fixes the contour generation to properly handle input data containing infinite values. The marching squares algorithm now skips quadrilaterals with non-finite corners instead of producing invalid output or raising errors.

Key change:

  • contour: Skip quads with any non-finite (NaN, +inf, -inf) corner values during contour line generation

AI-assisted review

  • I ran the xarray-spatial AI-assisted review workflow for this PR.
  • I reviewed the AI output myself and made my own judgment about what to accept.
  • I understand this change and can maintain it.
  • This PR does not attribute authorship to an AI tool or service.

AI-assisted review notes

The xarray-spatial review workflow was run against this change.

Issues found and addressed:

  • Added regression tests for contour handling of infinite values (np.inf, -np.inf)
  • Verified no change to public API behavior
  • Confirmed existing NaN handling remains correct

Open concerns:

  • None identified

Tests

Added tests in test_contour.py covering:

  • Contour generation with np.inf values in input arrays
  • Contour generation with -np.inf values in input arrays
  • Mixed finite and infinite value scenarios

@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 31, 2026
@github-actions
Copy link
Copy Markdown

Hi @Melissari1997, thanks for the PR!

Would you mind filing a quick New contributor introduction issue when you get a chance? It helps us point you at issues that fit what you'd like to work on. Most fields are optional.

Reviewing your PR doesn't depend on it, just a friendly nudge.

@Melissari1997 Melissari1997 changed the title Fix/2704 contours infinite nan coords contours: handle infinite nan coords May 31, 2026
…ay-contrib#2704)

After rebasing onto the upstream commit that introduced TestInfHandling
with xfail(strict=True) markers, the branch ended up with two classes of
the same name in test_contour.py. Python silently shadows the first
definition, so pytest only collected the second (upstream) class, which
still carried the xfail markers. The now-fixed np.isfinite guard caused
those tests to pass, producing XPASS(strict) CI failures on macOS/3.14.

- Remove the duplicate TestInfHandling block introduced by the rebase
- Drop the xfail(strict=True) decorators from test_inf_corner_no_nan_coords
@Melissari1997 Melissari1997 force-pushed the fix/2704-contours-infinite-nan-coords branch from d0d46f5 to e11043e Compare May 31, 2026 13:16
@Melissari1997
Copy link
Copy Markdown
Contributor Author

Apparently my fork wasn't in sync with the official repo

@brendancol brendancol merged commit 60eba44 into xarray-contrib:main Jun 1, 2026
7 checks passed
@Melissari1997 Melissari1997 deleted the fix/2704-contours-infinite-nan-coords branch June 1, 2026 06:04
@brendancol brendancol mentioned this pull request Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

contours() emits NaN coordinates for rasters containing +inf/-inf

2 participants