Skip to content

reproject: validate raster inputs in public APIs#1432

Merged
brendancol merged 2 commits into
mainfrom
issue-1431
May 4, 2026
Merged

reproject: validate raster inputs in public APIs#1432
brendancol merged 2 commits into
mainfrom
issue-1431

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Closes #1431.

Summary

  • reproject(): replace inline isinstance guard with _validate_raster(raster, ndim=(2, 3)).
  • merge(): validate each element of the input list.
  • geoid_height_raster(): add _validate_raster at the top of the function.
  • Update existing test_non_dataarray_raises regex to match the new error message.

Bad inputs (1-D DataArray, complex dtype, non-DataArray) previously crashed inside helpers with cryptic errors. They now raise TypeError / ValueError from the public API.

Test plan

  • pytest xrspatial/tests/test_reproject.py — 101 passed (96 existing + 5 new).
  • CI run on full suite.

reproject() and geoid_height_raster() previously checked only
isinstance(raster, xr.DataArray) and then accessed raster.coords /
raster.dims, so 1-D DataArrays and complex-dtype rasters failed
inside helpers with cryptic IndexError / KeyError.  merge() did
not validate elements at all, so a non-DataArray entry surfaced as
AttributeError on .data.

Replace the inline isinstance guard in reproject() and add per-
element validation in merge() with _validate_raster (ndim=(2, 3)).
Add the same call at the top of geoid_height_raster.

Update existing test_non_dataarray_raises to match the new error
message.  5 new tests in TestValidateRasterInputs.
@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 resolve the merge conflicts in this pull request

# Conflicts:
#	xrspatial/reproject/__init__.py
#	xrspatial/tests/test_reproject.py

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

Copilot AI commented May 4, 2026

@copilot resolve the merge conflicts in this pull request

Merge conflicts resolved in commit 004d36f. Both sets of changes are preserved:

  • merge() in __init__.py now has both the _validate_raster loop (from this PR) and the _validate_grid_params call (from main).
  • test_reproject.py retains all test classes from both branches (TestValidateRasterInputs, TestValidateGridParams, TestValidateMergeGridParams, TestItrfFiniteness, TestGeoidFiniteness, TestNodataFiniteness).

@brendancol brendancol merged commit bc90a2d into main May 4, 2026
1 check was pending
@brendancol brendancol deleted the issue-1431 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: missing _validate_raster on public API inputs

2 participants