Skip to content

reproject: validate grid/bounds/precision params#1434

Merged
brendancol merged 2 commits intomainfrom
issue-1433
May 4, 2026
Merged

reproject: validate grid/bounds/precision params#1434
brendancol merged 2 commits intomainfrom
issue-1433

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

@brendancol brendancol commented May 3, 2026

Closes #1433.

Summary

  • New _validate_grid_params() helper in xrspatial/reproject/_grid.py that range-checks resolution, bounds, width, height, transform_precision.
  • Wired into reproject() and merge() (the latter only validates the params that reach it).
  • Bad inputs now raise ValueError from the public API instead of ZeroDivisionError / IndexError deep in the resampler or silently producing wrong-signed coords.

Test plan

  • 24 new tests in TestValidateGridParams / TestValidateMergeGridParams.
  • pytest xrspatial/tests/test_reproject.py — 120 passed (96 existing + 24 new).
  • CI run on full suite.

reproject() and merge() accept several user-controlled grid
parameters that previously raised ZeroDivisionError or IndexError
deep in the resampler, or silently produced backwards coords:

- resolution=0 / NaN / Inf / negative: ZeroDivisionError or wrong-
  signed res_x.
- width / height = 0 / negative: ZeroDivisionError or silently
  inverted output.
- bounds with right<=left or top<=bottom: produced descending
  output coords and all-nodata silently.
- transform_precision=-1: IndexError on empty np.linspace.

Add _validate_grid_params() helper in _grid.py and call from both
reproject() and merge() before any helper consumes these values.

24 new tests in TestValidateGridParams / TestValidateMergeGridParams.
@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
Copy link
Copy Markdown
Contributor Author

@copilot can you fix the merge conflict?

Co-authored-by: brendancol <433221+brendancol@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented May 4, 2026

@copilot can you fix the merge conflict?

Fixed in commit 1789619. The conflict was in test_reproject.py where both branches appended new test classes at the end — resolved by keeping all sections from both sides (#1433 grid/bounds/precision tests and #1435 NaN/Inf tests).

@brendancol brendancol merged commit 2574157 into main May 4, 2026
1 check passed
@brendancol brendancol deleted the issue-1433 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.

reproject: grid/bounds/precision parameters not validated

2 participants