zonal: make apply() output .name deterministic across backends#2622
Merged
brendancol merged 2 commits intoMay 29, 2026
Merged
Conversation
brendancol
commented
May 29, 2026
Contributor
Author
brendancol
left a comment
There was a problem hiding this comment.
PR Review: zonal: make apply() output .name deterministic across backends
Blockers (must fix before merge)
None.
Suggestions (should fix, not blocking)
None.
Nits (optional improvements)
- The new
nameparameter goes at the end of the signature, afterrasterize_kw. That keeps existing positional calls working and matches howregions/trim/cropexposename, so it is fine as-is. Noting the placement was a deliberate compatibility choice.
What looks good
- Root cause is correct:
xr.DataArray(dask_array, name=None)inherits the dask graph's task name, so assigning.nameafter construction is the right fix. Setting it at construction time does not override the dask name. - The test runs on all four backends and checks both the default (
None) and an explicit name, which is exactly the inconsistency being fixed. - Attrs, dims, and coords handling is untouched; only
.namechanged. - The code comment explains why the assignment happens after construction, which is the non-obvious part.
Checklist
- Algorithm matches reference/paper: n/a (metadata fix)
- All implemented backends produce consistent results: yes, verified by the new parametrized test
- NaN handling is correct: unchanged by this PR
- Edge cases covered by tests: name default and explicit name both tested
- Dask chunk boundaries handled correctly: unchanged
- No premature materialization or unnecessary copies: confirmed, no compute added
- Benchmark exists or is not needed: not needed
- README feature matrix updated: not applicable, no new function
- Docstrings present and accurate: the new
nameparameter is documented
…y-contrib#2611) apply() never set the result name, so numpy/cupy returned None while the dask backends inherited an internal dask task name (also non-deterministic between runs). Add a name parameter (default None) and assign it after constructing the DataArray so the name is identical on all four backends.
263caf1 to
f2dee0e
Compare
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.
Closes #2611
What changed
zonal.apply()now sets a deterministic.nameon its output and accepts anameparameter (defaultNone), matchingregions,hypsometric_integral,trim, andcrop.xr.DataArray(dask_array, name=None)otherwise inherits the dask graph's internal task name, which differs from the numpy/cupy backends and changes between runs.Backend coverage
numpy, cupy, dask+numpy, dask+cupy. The new test runs on all four; before this change the two dask backends returned a task-hash name while numpy/cupy returned
None.Test plan
test_apply_name_consistent_across_backends(new): default name isNoneand an explicitname=is honored on every backendxrspatial/zonal.pyand the added test lines