Skip to content

Add dasymetric test coverage: metadata, 1x1, Inf weight, 3-class limiting_variable#3419

Open
brendancol wants to merge 3 commits into
xarray-contrib:mainfrom
brendancol:deep-sweep-test-coverage-dasymetric-2026-06-20
Open

Add dasymetric test coverage: metadata, 1x1, Inf weight, 3-class limiting_variable#3419
brendancol wants to merge 3 commits into
xarray-contrib:mainfrom
brendancol:deep-sweep-test-coverage-dasymetric-2026-06-20

Conversation

@brendancol

Copy link
Copy Markdown
Contributor

Closes #3407.

Test-only additions to xrspatial/dasymetric.py coverage, found by the test-coverage sweep. No source changes.

  • TestMetadataPreservation: assert attrs (res/crs) and coords carry through disaggregate and pycnophylactic (the old metadata test only checked dims/name/shape). Covers numpy and dask.
  • TestSinglePixel: true 1x1 raster for both functions (the existing case was a 1x2 strip). 1x1 is the degenerate kernel case for pycnophylactic where no neighbour shift runs.
  • TestInfWeight: pin the current behaviour for a +inf weight, which collapses a zone total to 0 (silent conservation break).
  • TestLimitingVariableThreeClass: three-class limiting_variable with per-class caps. Only the 2-class break was tested before, despite the docstring describing three-class dasymetric.
  • TestPycnophylacticEmptyValid: xfail(strict) tests pinning a crash bug the sweep found, filed as pycnophylactic raises opaque ValueError on all-NaN zones or no matching zone id #3406. pycnophylactic raises ValueError (np.nanmax on a zero-size array) when no pixel is valid for smoothing (all-NaN zones, or no zone id present in values); disaggregate returns all-NaN on the same input. The xfail flips red once pycnophylactic raises opaque ValueError on all-NaN zones or no matching zone id #3406 is fixed.

Backends: numpy and dask+numpy run locally. cupy / dask+cupy backends for disaggregate are already covered by the existing TestCrossBackend equivalence tests, so no new GPU variants were added.

Test plan:

@brendancol brendancol left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

PR Review: Add dasymetric test coverage (metadata, 1x1, Inf weight, 3-class limiting_variable)

Test-only PR. No source files changed, so the correctness risk is low and the review focuses on whether the tests pin the right behaviour.

Blockers (must fix before merge)

None.

Suggestions (should fix, not blocking)

  • The two xfail(strict) tests in TestPycnophylacticEmptyValid depend on #3406 staying open. Once #3406 is fixed the strict marker flips them red (XPASS), which is the intended signal to remove the marker. The test PR is already cross-linked from the #3406 body, so whoever fixes the bug will know to drop the markers. Informational.

Nits (optional improvements)

  • test_inf_weight_collapses_zone emits a RuntimeWarning: invalid value encountered in divide from dasymetric.py:206. The module already raises this warning in normal operation and the existing tests don't suppress it, so leaving it matches the file's style. Wrapping the call in np.errstate(invalid='ignore') would give a clean pytest run, but it's not required.
  • TestMetadataPreservation and TestSinglePixel cover numpy and dask but not cupy. The cupy dispatch is already exercised by TestCrossBackend, so this is fine; a cupy metadata assertion would be the only marginal gain and isn't worth a GPU-only test on its own.

What looks good

  • Reference values are concrete, not just "runs without crashing": 1x1 returns the full zone value, the 3-class case checks the 0/5/145 split and conservation, and the Inf case pins the exact NaN/0 collapse.
  • The discovered crash bug was filed separately (#3406) and pinned with xfail(strict, raises=ValueError) rather than bundled into a source fix. That keeps the test PR honest and gives the fix a built-in regression guard.
  • 1x1 dask-vs-numpy parity test covers the degenerate chunk case.

Checklist

  • Algorithm matches reference: n/a (test-only)
  • All implemented backends produce consistent results: existing cross-backend tests cover cupy/dask+cupy; new tests add numpy/dask metadata + 1x1 parity
  • NaN handling is correct: all-NaN disaggregate asserted all-NaN; pycnophylactic crash pinned via xfail
  • Edge cases covered: 1x1, Inf weight, 3-class caps, empty-valid
  • Dask chunk boundaries handled: 1x1 dask parity test
  • No premature materialization: n/a (test-only)
  • Benchmark exists or not needed: not needed
  • README feature matrix: not applicable (no new public API)
  • Docstrings present and accurate: each new test class has a docstring explaining intent and issue link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test coverage gaps in dasymetric: metadata preservation, 1x1 raster, Inf weight, 3-class limiting_variable

1 participant