Skip to content

hydro: add _validate_raster on secondary DataArray args#1426

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

hydro: add _validate_raster on secondary DataArray args#1426
brendancol merged 1 commit intomainfrom
issue-1425

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Closes #1425.

Summary

  • Adds _validate_raster on the secondary DataArray arg of 13 hydro public functions: watershed_* / snap_pour_point_d8 (pour_points), flow_path_* (start_points), stream_link_* / stream_order_* (flow_accum).
  • Bad input now raises TypeError / ValueError from the public API instead of an AttributeError from inside the implementation.

Test plan

  • pytest xrspatial/hydro/tests/test_validate_secondary_args.py — 13 new passes covering every touched function.
  • pytest xrspatial/hydro/tests/ — 774 + 13 = 787 passed.
  • CI run on full suite.

Each of the following public functions previously validated only its
primary raster.  A non-DataArray, 1-D DataArray, or None for the
secondary arg raised a confusing AttributeError / IndexError from
inside the implementation rather than a clean ValueError from the
public API.

Functions touched (secondary arg in parens):
- watershed_d8 / watershed_dinf / watershed_mfd (pour_points)
- snap_pour_point_d8 (pour_points)
- flow_path_d8 / flow_path_dinf / flow_path_mfd (start_points)
- stream_link_d8 / stream_link_dinf / stream_link_mfd (flow_accum)
- stream_order_d8 / stream_order_dinf / stream_order_mfd (flow_accum)

13 new tests in test_validate_secondary_args.py confirm each function
rejects a numpy ndarray for its secondary arg.
@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 d3f3b1f into main May 4, 2026
11 checks passed
@brendancol brendancol deleted the issue-1425 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: missing _validate_raster on secondary DataArray args

1 participant