test(rasterize): close public-API coverage gaps (deep-sweep pass 1)#2022
Conversation
Add 34 tests in test_rasterize_coverage_2026_05_17.py closing documented but untested surface flagged by the test-coverage sweep on 2026-05-17. - Cat 3 HIGH: 1x1 single-pixel raster across all four backends. test_rasterize.py covers 1xN strips and Nx1 strips but never the width=1 AND height=1 case, so the polygon scanline, line Bresenham, and point-burn kernels ship without the single-cell degenerate case. - Cat 4 HIGH: like= template-raster parameter (rasterize.py:2038) is implemented by _extract_grid_from_like (line 1930) but no test exercises it. Pins dtype/bounds/coords inheritance, the three override branches, the three validation branches, and like= on all four backends. Mutation against rasterize.py:2183-2184 flipped the inheritance test red. - Cat 4 HIGH: resolution= happy path. Only the oversize-rejection error path was tested; pins the scalar branch, the tuple branch, the ceil-and-clamp-to-1 semantics, and resolution= on all four backends. - Cat 4 HIGH: non-empty GeometryCollection unpacking is documented at rasterize.py:1995 and implemented by _classify_geometries_loop (line 228) but only the empty-GC case was tested. Pins polygon+point and polygon+line+point collections plus parity across cupy / dask+numpy / dask+cupy. - Cat 1 MEDIUM: eager cupy all_touched=True parity vs eager numpy. The existing parity test only covered dask+cupy all_touched. - Cat 2 MEDIUM: int32 dtype with default NaN fill silently casts to the int32-min sentinel. Pin the cast so any future raises-instead switch is visible as a code-review diff. Sweep is test-only: no source files modified. Pre-existing 143 passing plus 2 skipped tests in test_rasterize.py remain untouched.
The int32-default-NaN-fill test pinned a literal INT32_MIN sentinel. That value is platform-dependent: x86 yields INT32_MIN, Apple Silicon yields 0. Both are unspecified by C and by numpy, so the test now derives the expected sentinel from a runtime numpy cast and asserts rasterize emits the same value. CI on macos-latest, 3.14 was failing because the value there is 0, not INT32_MIN.
PR Review: test(rasterize): close public-API coverage gaps (deep-sweep pass 1)Reviewed locally on the worktree. This is a true test-only PR (only BlockersNone. Suggestions
Nits
What looks good
Checklist
|
Pin absolute burn values on cupy / dask / dask+cupy parity tests so a co-regression on both backends can't slip past a pure parity check. Tighten test_like_bounds_override to compare expected cell centres instead of just value ranges, and swap the GeometryCollection polygon+line+point line for a 45-degree diagonal so Bresenham steps in both axes. Document TestIntegerDtypeNanFill as numpy-only. Plus rename parity tests with a _matches_numpy suffix, cross-reference the two like= validation tests (same compound guard), trim brittle source-file line numbers from the module docstring, and drop the unused dask.array as da alias.
Summary
Closes documented but untested public-API surface in
xrspatial.rasterizeflagged by the test-coverage sweep on 2026-05-17. Adds 34 tests inxrspatial/tests/test_rasterize_coverage_2026_05_17.py. Sweep is test-only; no source files modified.Coverage gaps closed:
test_rasterize.pycovers 1xN strips and Nx1 strips but never thewidth=1ANDheight=1case, so the polygon scanline, line Bresenham, and point-burn kernels ship without the single-cell degenerate case.like=template-raster parameter (rasterize.py:2038) is implemented by_extract_grid_from_like(line 1930) but no test exercises it. Pins dtype/bounds/coords inheritance, the three override branches (dtype,bounds,width/height), the three validation branches (not-DataArray, 3D, wrong dim names), andlike=on all four backends. Mutation againstrasterize.py:2183-2184flipped the inheritance test red.resolution=happy path. Only the oversize-rejection error path was tested (test_oversize_resolution_rejected); pins the scalar branch, the tuple branch, the ceil-and-clamp-to-1 semantics, andresolution=on all four backends.GeometryCollectionunpacking is documented atrasterize.py:1995and implemented by_classify_geometries_loop(line 228) but only the empty-GC case was tested. Pins polygon+point and polygon+line+point collections plus parity across cupy / dask+numpy / dask+cupy.all_touched=Trueparity vs eager numpy. The existing parity test only covered dask+cupyall_touched, leaving the direct GPUall_touchedkernel untested.Test plan
test_rasterize.pyremain green.like=dtype inheritance branch (elif like_dtype is not None: final_dtype = like_dtype) flips the inheritance test red, confirming the new coverage catches a real regression.