Fixes #903: add comprehensive input validation across public API#912
Merged
brendancol merged 1 commit intomasterfrom Feb 27, 2026
Merged
Fixes #903: add comprehensive input validation across public API#912brendancol merged 1 commit intomasterfrom
brendancol merged 1 commit intomasterfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_validate_raster()and_validate_scalar()utilities toutils.pythat provide consistent, user-friendly error messages with function name, parameter name, and expected-vs-actual valuesisinstance/ndim/dtypechecks infocal.py,zonal.py, andcost_distance.pywith unified callstest_validation.pywith 74 systematic tests covering type, ndim, dtype, scalar range, and integer-only checksTest plan
pytest xrspatial/tests/test_validation.py)test_zonal.pyerror message match ("integers"→"integer dtype")pytest xrspatial/tests/ --ignore=xrspatial/tests/test_gpu)