-
Notifications
You must be signed in to change notification settings - Fork 85
Closed
Labels
apiAPI design and consistencyAPI design and consistencyenhancementNew feature or requestNew feature or requestinput-validationInput validation and error messagesInput validation and error messages
Description
Problem
Input validation is inconsistent across the library. Some functions do thorough checking (e.g., zonal.crosstab validates types, dimensions, and shapes), while many others do no validation at all and produce cryptic errors.
Examples
slope(),aspect(),hillshade(),curvature(): No validation that input is 2D, no check for numeric dtype. Passing a string array or 3D array produces a confusing numbaTypingErrordeep in JIT-compiled code.proximity(): Validates dims match but doesn't check that coordinates are monotonically increasing (required for correct distance calculation).cost_distance(): No validation that friction surface has matching shape/chunks.multispectral.*: Validates array shapes match but not that values are in expected ranges.
The diagnostics.py module exists but is not integrated into any function.
Proposed Fix
-
Add
_validate_raster(agg, ndim=2, name='raster')utility inxrspatial/utils.pythat checks:- Is a DataArray
- Correct ndim
- Numeric dtype
- Has coordinates
- Coordinates are monotonic (where required)
-
Call at the top of each public function with function-specific constraints.
-
Ensure all error messages include: function name, parameter name, expected type/value, actual type/value.
Scope
This is a mechanical change across many files, but each individual change is small. Could be split into per-module PRs.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
apiAPI design and consistencyAPI design and consistencyenhancementNew feature or requestNew feature or requestinput-validationInput validation and error messagesInput validation and error messages