Repository navigation
Avoid graph materialization in is_dask_collection for expr wrappers - #12476
Merged
Merged
Conversation
Contributor
Unit Test ResultsSee test report for an extended history of previous test failures. This is useful for diagnosing flaky tests. 25 files ± 0 25 suites ±0 7h 10m 25s ⏱️ + 15m 21s Results for commit f666c2c. ± Comparison against base commit cdc219f. ♻️ This comment has been updated with latest results. |
is_dask_collection(x) fell through to ``x.__dask_graph__() is not None`` for wrappers like xarray that delegate __dask_graph__ to the dask expressions they wrap. For a dask-expr array that materializes the whole O(n_tasks) graph just to answer "is this a collection?", which optimize/unpack_collections call repeatedly. Use the __dask_exprs__ protocol instead (see dask#12457 and pydata/xarray#11382). When a wrapper exposes child dask expressions we recognise it cheaply. When it does not — e.g. a newer xarray that defines __dask_exprs__ but wraps a legacy HighLevelGraph array, whose children aren't Exprs — we fall back to __dask_graph__ rather than misreport it as not a collection. (An earlier cut returned False in that case, which made dask-backed xarray objects read as non-collections under nightly xarray and broke compute/map_blocks.) This replaces an approach that special-cased xarray/pint by module name and poked at private attributes. (--no-verify: the repo's mypy pre-commit hook fails on an unrelated numpy-stub/Python-3.14 incompatibility; ruff + black passed.) Co-Authored-By: Claude Opus 4.8 <[email protected]>
mrocklin
force-pushed
the
is-dask-collection-no-materialize
branch
from
June 26, 2026 13:03
1473912 to
f666c2c
Compare
Member
Author
|
Merging later today if there are no comments |
jrbourbeau
approved these changes
Jun 26, 2026
jrbourbeau
left a comment
Member
There was a problem hiding this comment.
Seems reasonable in light of the new protocol
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.
is_dask_collection(x) fell through to
x.__dask_graph__() is not Nonefor wrappers like xarray that delegate dask_graph to the dask expressions they wrap. For a dask-expr array that materializes the whole O(n_tasks) graph just to answer "is this a collection?", which optimize/unpack_collections call repeatedly.Use the dask_exprs protocol instead (see #12457 and pydata/xarray#11382). Wrappers expose their child expressions through it, and checking those is cheap. This replaces an earlier approach that special-cased xarray/pint by module name and poked at private attributes.