Skip to content

contours: handle infinite nan coords#2749

Open
Melissari1997 wants to merge 2 commits into
xarray-contrib:mainfrom
Melissari1997:fix/2704-contours-infinite-nan-coords
Open

contours: handle infinite nan coords#2749
Melissari1997 wants to merge 2 commits into
xarray-contrib:mainfrom
Melissari1997:fix/2704-contours-infinite-nan-coords

Conversation

@Melissari1997
Copy link
Copy Markdown

@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
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