Fix cost_distance leaking dask task name as output .name#3349
Merged
Conversation
The dask+numpy and dask+cupy backends surfaced the internal dask graph name (e.g. _trim-... from map_overlap, asarray-... from dask+cupy) as the returned DataArray .name, while numpy and cupy returned name=None. Force the result name to the input raster's name with .rename() so all four backends agree. Passing name= to the constructor is insufficient because xarray treats name=None as 'infer from data'. Adds a parametrized regression test across all four backends and both named and unnamed inputs.
brendancol
commented
Jun 15, 2026
brendancol
left a comment
Contributor
Author
There was a problem hiding this comment.
PR Review: Fix cost_distance leaking dask task name as output .name
Blockers
None.
Suggestions
None.
Nits
None.
What looks good
- The fix is minimal and correct.
.rename(raster.name)is the right tool: I confirmed that passingname=Noneto thexr.DataArrayconstructor does not override a dask array's internal name, but.rename(None)does force it, so the constructor-only approach would not have fixed the unnamed-input case. - Only
.namechanges; data, coords, dims, and attrs are untouched. - The regression test runs all four backends and both named and unnamed inputs (8 cases). On this CUDA host none of them skip, so the cupy and dask+cupy paths are genuinely exercised.
- The
supports_datasetpath is unaffected: a Dataset input calls the function per variable withraster.namealready equal to the variable name, so the rename keeps the variable key. Verified by running a Dataset through the dask backend. - The inline comment explains the non-obvious reason
.renameis needed instead of a constructorname=, which will save the next reader a debugging session.
Checklist
- Behavior matches intent (name consistent across backends)
- All four backends produce consistent .name
- No data/coords/dims/attrs regression
- Edge cases covered (named + unnamed input, all backends)
- No premature materialization or extra copies (rename is metadata-only)
- Benchmark not needed (metadata-only fix)
- README / docs not applicable (no API change)
…ost_distance-2026-06-15
…ost_distance-2026-06-15
…ost_distance-2026-06-15 # Conflicts: # xrspatial/tests/test_cost_distance.py
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 #3344
cost_distancereturned a DataArray whose.namedepended on the backend: numpy and cupy gavename=None, but dask+numpy and dask+cupy leaked the internal dask graph name (_trim-...,asarray-...) as the user-visible.name. That token is random per run, so.to_dataset()and any name-keyed logic became nondeterministic on the dask paths..rename(raster.name). Passingname=to the constructor isn't enough because xarray treatsname=Noneas "infer from data" and lets the dask token through.Backends: numpy, cupy, dask+numpy, dask+cupy all verified (CUDA host).
Test plan:
test_result_name_matches_inputpasses on all four backends (8 cases, no skips on this GPU host)test_cost_distance.pysuite passes (63 passed)