Skip to content

Fixes #903: add comprehensive input validation across public API#912

Merged
brendancol merged 1 commit intomasterfrom
issue-903-input-validation
Feb 27, 2026
Merged

Fixes #903: add comprehensive input validation across public API#912
brendancol merged 1 commit intomasterfrom
issue-903-input-validation

Conversation

@brendancol
Copy link
Contributor

Summary

  • Add _validate_raster() and _validate_scalar() utilities to utils.py that provide consistent, user-friendly error messages with function name, parameter name, and expected-vs-actual values
  • Call validators at the top of every public function (~35 entry points across 15 modules): surface analysis, focal, proximity, cost_distance, zonal, classify, multispectral, viewshed, perlin, terrain, bump
  • Replace ad-hoc isinstance/ndim/dtype checks in focal.py, zonal.py, and cost_distance.py with unified calls
  • Add test_validation.py with 74 systematic tests covering type, ndim, dtype, scalar range, and integer-only checks

Test plan

  • All 74 new validation tests pass (pytest xrspatial/tests/test_validation.py)
  • Updated test_zonal.py error message match ("integers""integer dtype")
  • Full test suite passes: 1100 passed, 0 failed (pytest xrspatial/tests/ --ignore=xrspatial/tests/test_gpu)

Add _validate_raster() and _validate_scalar() utilities to utils.py and
call them at the top of every public function (~35 entry points across
15 modules). Invalid input now raises clear TypeError/ValueError with
function name, parameter name, and expected-vs-actual values instead of
cryptic numba TypingError deep in JIT kernels.

- _validate_raster: checks DataArray type, ndim, numeric/integer dtype
- _validate_scalar: checks scalar type (incl. numpy equivalents), range
- Replace ad-hoc isinstance/ndim checks in focal, zonal, cost_distance
- Add validation to all surface, proximity, classify, multispectral,
  viewshed, perlin, terrain, and bump functions
- Add test_validation.py with 74 systematic tests covering type, ndim,
  dtype, scalar range, and integer-only checks
@brendancol brendancol merged commit f5ce56a into master Feb 27, 2026
10 checks passed
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.

1 participant