Skip to content

slope: add degenerate-shape test coverage (1x1, 1xN, Nx1)#2703

Merged
brendancol merged 4 commits into
mainfrom
deep-sweep-test-coverage-slope-2026-05-29
May 30, 2026
Merged

slope: add degenerate-shape test coverage (1x1, 1xN, Nx1)#2703
brendancol merged 4 commits into
mainfrom
deep-sweep-test-coverage-slope-2026-05-29

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Closes #2697

Adds tests for degenerate raster shapes where a dimension is too small for the 3x3 kernel to have an interior. These shapes already work (output keeps the input shape and comes back all-NaN), but nothing pinned that down. A future change to the kernel bounds could start raising or returning the wrong shape and no test would catch it.

  • New test_degenerate_shape_* tests covering shapes (1, 1), (1, 5), (5, 1)
  • Planar method on all four backends (numpy, cupy, dask+numpy, dask+cupy), geodesic on numpy
  • Test-only change, no source modifications

Backend coverage: numpy, cupy, dask+numpy, dask+cupy.

Test plan:

  • pytest xrspatial/tests/test_slope.py -k degenerate -> 15 passed (cupy and dask+cupy ran on a CUDA host, not skipped)
  • pytest xrspatial/tests/test_slope.py xrspatial/tests/test_geodesic_slope.py -> 77 passed

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

@brendancol brendancol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review: slope degenerate-shape test coverage

Blockers

None.

Suggestions

None.

Nits

  • test_slope.py:215 The geodesic test asserts shape and all-NaN directly but skips general_output_checks, which test_degenerate_shape_numpy (line 165) calls. The cross-backend helpers already cover attrs/coords on the dask and cupy paths, so this is minor. Adding general_output_checks(raster, result) to the geodesic test would make the attrs/coords/dims check uniform across all five tests.

What looks good

  • All four planar backends plus geodesic are covered through the existing helpers in general_checks.py.
  • nan_edges=False is correct here. These outputs are entirely NaN, so assert_nan_edges_effect would have no non-NaN interior to compare against.
  • The comment explains why these shapes come back all-NaN (the range(1, rows-1) loop is empty when rows<=2), so the test pins a real contract instead of freezing whatever the code happens to return today.
  • Ran locally on a CUDA host: 15 degenerate tests passed, with cupy and dask+cupy actually executing rather than skipping.

Checklist

  • Test-only, no algorithm change
  • All implemented backends produce consistent results
  • NaN handling is correct
  • Edge cases covered
  • Dask chunk boundaries handled correctly
  • No premature materialization
  • Benchmark not needed; README matrix and docstrings not applicable

Copy link
Copy Markdown
Contributor Author

@brendancol brendancol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up review

The one nit from the first pass is resolved: the geodesic degenerate-shape test now calls general_output_checks(raster, result), so attrs/coords/dims preservation is asserted uniformly across all five degenerate tests (952062e).

No remaining Blockers, Suggestions, or Nits. Re-ran pytest xrspatial/tests/test_slope.py -k degenerate -> all pass.

@brendancol brendancol merged commit 79942c6 into main May 30, 2026
7 checks passed
brendancol added a commit that referenced this pull request May 31, 2026
- numpy degenerate-shape test now runs general_output_checks to assert
  attrs/coords/dims are preserved, matching the slope #2703 convention.
- add a geodesic degenerate-shape test (1x1, 1xN, Nx1) so the no-interior
  case is pinned for method='geodesic' too, not just planar.
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.

slope: add test coverage for degenerate-shape rasters (1x1, 1xN, Nx1)

1 participant