Make binary() output float32 on all backends#3514
Merged
brendancol merged 2 commits intoJun 26, 2026
Merged
Conversation
_cpu_binary allocated np.empty(..., dtype=data.dtype), so binary() returned the input dtype on numpy/dask+numpy while cupy/dask+cupy always returned float32. Allocate float32 in _cpu_binary so all four backends agree and so the NaN sentinel for non-finite cells is representable on integer input. Matches _cpu_bin and the other classifiers. Add cross-backend dtype regression tests.
Address PR review: the existing binary backend tests called general_output_checks without verify_dtype, so the cupy/dask+cupy output dtype was unasserted. Pass verify_dtype=True (matching the reclassify tests) to lock the float32 contract across all four backends.
Contributor
Author
PR Review: Make binary() output float32 on all backendsBlockersNone. Suggestions
Nits
What looks good
DuplicatePR #3513 (metadata sweep) fixes the same Checklist
|
brendancol
added a commit
to brendancol/xarray-spatial
that referenced
this pull request
Jun 26, 2026
…array-contrib#3508) The _cpu_binary float32 fix and the verify_dtype=True backend tests landed on main via the duplicate accuracy-sweep PR xarray-contrib#3514. This change is the remaining piece: _run_dask_cupy_binary passed meta=cupy.array(()), which defaults to float64, so the lazy dask+cupy array advertised float64 while _run_cupy_binary computes float32. The merged tests only check the computed dtype (general_output_checks computes before asserting), so the mismatch went unnoticed. Pass meta=cupy.array((), dtype='f4') and assert the lazy dtype in test_binary_dask_cupy. Same advertised-vs-computed class as aspect xarray-contrib#2682 and focal xarray-contrib#3217. Also records the classify metadata-propagation sweep state.
brendancol
added a commit
that referenced
this pull request
Jun 26, 2026
…3508) (#3513) The _cpu_binary float32 fix and the verify_dtype=True backend tests landed on main via the duplicate accuracy-sweep PR #3514. This change is the remaining piece: _run_dask_cupy_binary passed meta=cupy.array(()), which defaults to float64, so the lazy dask+cupy array advertised float64 while _run_cupy_binary computes float32. The merged tests only check the computed dtype (general_output_checks computes before asserting), so the mismatch went unnoticed. Pass meta=cupy.array((), dtype='f4') and assert the lazy dtype in test_binary_dask_cupy. Same advertised-vs-computed class as aspect #2682 and focal #3217. Also records the classify metadata-propagation sweep state.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
binary()returned the input dtype on the numpy and dask+numpy backends but always float32 on cupy and dask+cupy. This allocates float32 in_cpu_binaryso the result dtype matches across all four backends, which is what the cupy path and every other classifier already do.Why
_cpu_binaryallocatednp.empty(data.shape, dtype=data.dtype). For a float64 input the numpy and dask results were float64 while the cupy results were float32. Integer input was worse: the array cannot store the NaN thatbinarywrites for non-finite cells.Changes
_cpu_binaryallocates a float32 output.test_binary_output_dtype_float32andtest_binary_dask_output_dtype_float32.Testing
pytest xrspatial/tests/test_classify.pypasses (104 tests, numpy/dask/cupy/dask+cupy).Closes #3511.