Add rasterize() validation-guard test coverage (#3383)#3385
Conversation
Cover the input-validation guards in rasterize() that had no error-path tests: non-representable integer/bool fill, burn values above the float64 safe-integer range, non-finite burn values into integer/bool dtypes (with the merge='count' exemption), and non-finite geometry coordinates dropped with a warning. Test-only; all guards run on the CPU path pre-dispatch. Also record the pass in the sweep-test-coverage state CSV.
brendancol
left a comment
There was a problem hiding this comment.
PR Review: Add rasterize() validation-guard test coverage (#3385)
Test-only PR. It adds four test classes to test_rasterize.py covering input-validation guards in rasterize() that had no error-path tests. No source changes. I read the new tests and the four guards they exercise (rasterize.py lines 4378-4487 and 230-265).
Blockers (must fix before merge)
None.
Suggestions (should fix, not blocking)
None.
Nits (optional improvements)
test_nonfinite_geometry_in_gdf_dropped_with_warningalso triggers a shapelyRuntimeWarning("invalid value encountered in bounds") next to the expectedUserWarning.pytest.warnsmatches on at least one warning so the test passes, but the stray warning lands in the pytest warnings summary. Could wrap the GeoDataFrame construction inwarnings.simplefilterto keep the summary clean. Not worth blocking on.
What looks good
- Each guard is paired with a negative case (valid integer/bool/float fill, the
2**53-1boundary, themerge='count'exemption, float-dtype burn), so the tests confirm the guards are narrow rather than just that they reject. - The
match=regexes line up with the real error substrings in the source. - The non-finite burn test parametrizes nan / +inf / -inf instead of testing one.
- The PR is right that the guards run on the CPU path before backend dispatch, so no GPU or cross-backend parity test is needed. All three validation blocks run before the
chunks/gpubranch inrasterize().
Checklist
- NaN handling: tests assert both the reject paths and the float-dtype accept paths.
- Edge cases: this PR is the edge-case coverage.
- Docstrings: each test class has a docstring citing the guarded issue.
- Backend parity / dask / benchmark / README matrix: not applicable (test-only, guards are pre-dispatch).
brendancol
left a comment
There was a problem hiding this comment.
Follow-up review (#3385)
Addressed the single nit from the first pass. test_nonfinite_geometry_in_gdf_dropped_with_warning now carries a @pytest.mark.filterwarnings for the incidental shapely "invalid value encountered in bounds" RuntimeWarning, so it no longer shows up in the pytest warnings summary. The expected UserWarning assertion is unchanged.
Re-ran the module: 233 passed, 2 skipped (the 2 remaining warnings are the pre-existing GPU custom-merge UserWarnings, not from this PR).
No outstanding findings. Disposition: 1 nit fixed, 0 dismissed, 0 deferred.
Closes #3383.
Adds error-path tests for the
rasterize()input-validation guards that had no coverage. The guards all run on the CPU path before backend dispatch, so the tests need no GPU.TestFillRepresentableGuard: NaN fill into an integer dtype, an out-of-range integer fill intouint8, and a non-False fill intoboolare rejected (rasterize: silent NaN-to-integer fill cast loses sentinel, no _FillValue emitted #2504 / rasterize: integer/boolean fill can silently corrupt output and nodata attrs #3054). Negative cases confirm valid integer/bool fills and a float NaN fill still pass.TestBurnValueSafeIntegerGuard: a burn value with|value| > 2**53 - 1into an integer dtype is rejected (rasterize() loses precision on large integer burn values (float64 cast) #3056); the2**53 - 1boundary and float-dtype exemption pass.TestNonFiniteBurnValueGuard: NaN / +/-inf burn values into integer or bool dtypes are rejected (rasterize: NaN/inf burn values silently cast to INT_MIN under integer output dtype #3085); themerge='count'exemption and float-dtype path pass.TestNonFiniteGeometryCoordsDropped: a geometry with NaN / inf coordinates is dropped with aUserWarning(rasterize: NaN/inf and int32-overflowing coordinates burn phantom pixels #3295), covering the list and GeoDataFrame paths.Test-only. No source change.
Backend coverage: the guards are backend-independent (they fire before dispatch), so the tests exercise the shared CPU validation path. No new cupy / dask tests are needed.
Test plan:
test_rasterize.pymodule passes (233 passed, 2 skipped)