hydro: validate scalar parameters#1428
Merged
brendancol merged 1 commit intomainfrom May 4, 2026
Merged
Conversation
Several hydro public functions accepted scalar parameters that were not range-checked. Non-finite values and out-of-domain values passed the existing checks and produced silent wrong output (all-NaN rasters, no-op behavior, undefined comparisons). - flow_direction_mfd: replace 'p <= 0' with 'not (np.isfinite(p) and p > 0)' so NaN/Inf no longer slip through. - snap_pour_point_d8: enforce search_radius is a positive int. - hand_d8 / hand_dinf / hand_mfd: enforce np.isfinite(threshold). - fill_d8: enforce z_limit is non-negative finite or None. Updated test_invalid_p() and added 29 new parameterised cases in test_validate_scalar_params.py.
brendancol
added a commit
that referenced
this pull request
May 3, 2026
Records the 11 PRs filed this round: - hydro: HIGH flow_direction_mfd memory guard (PR #1424); MEDIUM bundles for _validate_raster on secondary args (#1426), scalar param validation (#1428), and cellsize validation (#1430). - reproject: MEDIUM bundles for _validate_raster (#1432), grid/bounds/ precision validation (#1434), and NaN/Inf rejection (#1436). - flood: mannings_n DataArray validation (#1438). - pathfinding: waypoint cap + _validate_raster (#1440). - polygonize: _validate_raster (#1442). - terrain: scratch memory guard + scalar validation (#1444).
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.
Closes #1427.
Summary
flow_direction_mfdp exponent: replacep <= 0with finite + positive check (NaN/Inf no longer pass).snap_pour_point_d8search_radius: enforce positive integer.hand_d8/hand_dinf/hand_mfdthreshold: enforce finite.fill_d8z_limit: enforce non-negative finite or None.Each case previously produced silent wrong output (all-NaN raster, no-op, etc.) on bad input.
Test plan
test_invalid_p()for the new wording.test_validate_scalar_params.py.