FIX keep inherited from builtin containers' types#9298
Open
adrinjalali wants to merge 2 commits into
Open
Conversation
Contributor
Unit Test ResultsSee test report for an extended history of previous test failures. This is useful for diagnosing flaky tests. 40 files ± 0 40 suites ±0 14h 21m 27s ⏱️ + 6m 0s For more details on these failures, see this check. Results for commit eb2f68a. ± Comparison against base commit db3cb43. ♻️ This comment has been updated with latest results. |
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author
|
It doesn't look like the failures are related to the PR. |
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.
This turned up in scikit-learn, where a
Bunchobject would get downgraded to adict, when thedaskbackend forjoblibwas used. We fixed the issue in scikit-learn by not using theBunchspecific features, but the core issue comes from here, and this PR fixes the issue.I think it would make sense to fix the core issue here.
pixi run lintfyi @tomMoral @StefanieSenger
Claude generated summary, feel free to ignore.
Preserve collection subclasses across
Client.scatterClient.scatterdecided whether to treat its argument as a single value or acollection of items to scatter using
isinstance. Becauseisinstance(some_dict_subclass, dict)isTrue, adictsubclass (e.g.scikit-learn's
Bunch) was unpacked as a mapping and returned as{key: Future},silently losing its type — list/set/tuple subclasses were reconstructed via
input_type(...), but dict subclasses were not.This switches the collection-vs-single decision to exact-type checks, so any
subclass of a builtin collection is scattered as a single opaque value (pickled,
exact type preserved). Exact
dict/list/set/tuple/frozensetkeep theirexisting "collection of items" behavior.
Background
scikit-learn's metadata routing passes a
Bunch(adictsubclass withattribute access) between estimators. Under
joblib's dask backend, argumentslarger than ~1 KB are implicitly scattered, so the
Bunchround-tripped throughscatterand arrived on the worker as a plaindict, breaking attribute access(
AttributeError: 'dict' object has no attribute ...).This was first worked around on the joblib side
(joblib/joblib#1798) by wrapping
such objects before scattering. Review feedback there asked, reasonably, why this
isn't fixed in dask directly — the downgrade happens because
scatterchooses tounpack the object, so
scattershould defend its own contract. This PR is thatfix; the joblib-side workaround can be dropped once it lands.
Non-regression for
scikit-learn/scikit-learn#34005.
Tests
test_scatter_collection_subclass: a dict subclass, list/set subclasses, and anamedtuple each scatter to a single
Futurewith their exact type preserved onthe worker (including attribute access).