Skip to content

Validate raster dtype in convolve_2d() (#1389)#1393

Merged
brendancol merged 1 commit into
mainfrom
issue-1389-convolve-2d-validate
Apr 30, 2026
Merged

Validate raster dtype in convolve_2d() (#1389)#1393
brendancol merged 1 commit into
mainfrom
issue-1389-convolve-2d-validate

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Closes #1389.

Summary

convolve_2d() skipped _validate_raster, so boolean, string, or wrong-ndim inputs reached numba/cupy and produced confusing internal errors. This wraps the input in xr.DataArray once and validates it before the kernel dispatch.

PR #1384 already taught _validate_raster to reject complex dtypes, so the single call covers boolean, string, and complex.

Changes

  • xrspatial/convolution.py: wrap input in xr.DataArray and call _validate_raster(agg, func_name='convolve_2d', ndim=2) at the top of convolve_2d(). The same DataArray feeds the existing ArrayTypeFunctionMapping dispatch.
  • xrspatial/tests/test_convolution.py: 4 new tests (boolean rejected, string rejected, 1D rejected, float64 still works).

Test plan

  • pytest xrspatial/tests/test_convolution.py passes (4/4)
  • pytest xrspatial/tests/test_focal.py still passes (134/134)

Wrap the input in xr.DataArray and run _validate_raster before the
kernel dispatch so boolean, string, complex, and wrong-ndim inputs
fail with a clear ValueError instead of a numba TypingError or a
cupy crash.

PR #1384 already taught _validate_raster to reject complex dtypes,
so a single call covers the whole non-numeric set.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label Apr 30, 2026
@brendancol brendancol merged commit 7b9d100 into main Apr 30, 2026
10 of 11 checks passed
@brendancol brendancol deleted the issue-1389-convolve-2d-validate branch May 4, 2026 13:04
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.

convolve_2d: missing _validate_raster on input

1 participant