Skip to content

hydro: validate cellsize before division#1430

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

hydro: validate cellsize before division#1430
brendancol merged 1 commit intomainfrom
issue-1429

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Closes #1429.

Summary

  • Adds a finite-and-non-zero check on cellsize_x / cellsize_y after every get_dataarray_resolution() call in xrspatial/hydro/.
  • Affected: twi_d8, flow_direction_d8 / _dinf / _mfd, flow_length_d8 / _dinf / _mfd.
  • Bad coords previously produced inf or zero output silently; now raise ValueError.

Test plan

  • pytest xrspatial/hydro/tests/test_validate_cellsize.py — 7 new passes.
  • pytest xrspatial/hydro/tests/ — 774 + 7 = 781 passed.
  • CI run on full suite.

twi_d8, flow_direction_d8/_dinf/_mfd, and flow_length_d8/_dinf/_mfd
all call get_dataarray_resolution() and divide by the result without
checking that the cellsize is finite and non-zero.  A 1-D-coord
DataArray (or one with NaN coords) silently produced inf or zero
output.

Add a finite-and-non-zero check at each of the seven call sites that
raises ValueError with a message naming the cellsize values.

7 new tests in test_validate_cellsize.py covering each function.
@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 e146aec into main May 4, 2026
11 checks passed
@brendancol brendancol deleted the issue-1429 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: cellsize not validated before division (silent miscompute)

1 participant