zonal: rechunk apply 3D dask output along stacked axis (#2526)#2532
Merged
Conversation
`zonal.apply` on a 3D dask `values` array calls `da.stack(layers, axis=2)` to assemble per-band `map_blocks` outputs. `da.stack` creates unit chunks along the new axis, and the function did not rechunk afterward, so the result had `chunks[2] = (1, 1, ..., 1)` regardless of the input chunking. Reproducing on 256x256 input with chunks=(64, 64, 3) confirmed output chunks of `(1, 1, 1)` instead of `(3,)`. Downstream operations that touch all bands together paid scheduling overhead proportional to the band count. Fix: rechunk the stacked output back to the input's axis-2 chunking in both `_apply_dask_numpy` and `_apply_dask_cupy`. Adds regression test `test_apply_dask_3d_axis2_rechunked_2526` and updates the sweep-performance state row for `zonal`.
Contributor
Author
ReviewTargeted fix, low risk. The Verified
Notes (not blocking)
Looks ready to merge. |
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
zonal.applyon a 3D daskvaluesarray left output chunks at size 1 along the stacked axis becauseda.stack(layers, axis=2)was not followed byrechunk().values_data.chunks[2]in both_apply_dask_numpyand_apply_dask_cupy.test_apply_dask_3d_axis2_rechunked_2526and updates the sweep-performance state row forzonal.Fixes #2526.
Background
Graph probe on a 256x256 raster with
chunks=(64, 64, 3)and 3 bands previously yielded:The documented anti-pattern from CLAUDE.md is
da.stackwithout a followingrechunk— see existing zonalhypsometric_integralaudit notes that called out the same shape.Test plan
pytest xrspatial/tests/test_zonal.py(126 passed)result.data.chunks[2] == values.data.chunks[2]test_apply_3d[dask+numpy]still passes