Skip to content

Validate dtypes per band in mahalanobis() (#1376)#1379

Merged
brendancol merged 1 commit into
mainfrom
issue-1376
Apr 30, 2026
Merged

Validate dtypes per band in mahalanobis() (#1376)#1379
brendancol merged 1 commit into
mainfrom
issue-1376

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

  • mahalanobis() only ran validate_arrays() on its bands, which checks matching shape and array-type but not dtype. Boolean and other non-numeric DataArrays were silently coerced to float64 instead of being rejected.
  • Call _validate_raster() on each band first, then the existing shape/array-type check, then the memory guard, then compute.
  • Closes mahalanobis: missing _validate_raster on bands #1376.

Changes

  • xrspatial/mahalanobis.py: import _validate_raster and loop over bands at the top of mahalanobis(), validating each as a 2-D numeric DataArray.
  • xrspatial/tests/test_mahalanobis.py: three tests covering the bool reject path, the string reject path, and the mixed-numeric (float + int) positive path.

Related

Test plan

  • pytest xrspatial/tests/test_mahalanobis.py -- 24 passed (21 prior + 3 new).

`mahalanobis()` relied solely on `validate_arrays()` for input
validation, which only checks matching shape and array-type.  Boolean
and other non-numeric DataArrays were silently coerced to float64.

Call `_validate_raster()` on every band before the existing checks so
non-numeric inputs raise a clear error at the API boundary.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label Apr 30, 2026
@brendancol brendancol merged commit 1822d25 into main Apr 30, 2026
11 checks passed
@brendancol brendancol deleted the issue-1376 branch May 4, 2026 19:50
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.

mahalanobis: missing _validate_raster on bands

1 participant