Skip to content

hydro: validate scalar parameters#1428

Merged
brendancol merged 1 commit intomainfrom
issue-1427
May 4, 2026
Merged

hydro: validate scalar parameters#1428
brendancol merged 1 commit intomainfrom
issue-1427

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Closes #1427.

Summary

  • flow_direction_mfd p exponent: replace p <= 0 with finite + positive check (NaN/Inf no longer pass).
  • snap_pour_point_d8 search_radius: enforce positive integer.
  • hand_d8 / hand_dinf / hand_mfd threshold: enforce finite.
  • fill_d8 z_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

  • Updated existing test_invalid_p() for the new wording.
  • 29 new parameterised cases in test_validate_scalar_params.py.
  • Full hydro suite: 803 passed.
  • CI run on full suite.

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.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 3, 2026
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).
@brendancol brendancol merged commit 796bd11 into main May 4, 2026
10 of 11 checks passed
@brendancol brendancol deleted the issue-1427 branch May 4, 2026 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hydro: scalar parameters not validated against NaN/Inf and bad ranges

1 participant