Skip to content

FIX metaedata routing with dask backend on joblib - #34077

Merged
OmarManzoor merged 4 commits into
scikit-learn:mainfrom
adrinjalali:slep6/bunch
Jun 9, 2026
Merged

OmarManzoor merged 4 commits into
scikit-learn:mainfrom
adrinjalali:slep6/bunch

Conversation

@adrinjalali

@adrinjalali adrinjalali commented May 21, 2026 •

Copy link
Copy Markdown
Member

Fixes #34005

In the process, found some inconsistencies wrt how we handle "empty requests", and this PR unifies them at the same time.

AI usage disclosure

I used AI assistance for:

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Research and understanding

cc @StefanieSenger

@adrinjalali adrinjalali added the Metadata Routing all issues related to metadata routing, slep006, sample props label May 21, 2026
Comment thread sklearn/pipeline.py
This should be of the form ``process_routing()["step_name"]``.
"""
res = transformer.transform(X, **params.transform)
res = transformer.transform(X, **params["transform"])

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what actually fixes the original issue trigering this work.

Comment thread sklearn/pipeline.py
Comment on lines +415 to +435
# Routing disabled: fit_params for a step are forwarded to whichever
# of fit/fit_transform/fit_predict the step's caller invokes.
per_step = {
name: {"fit": {}, "fit_transform": {}, "fit_predict": {}}
for name, step in self.steps
if step is not None
}
for pname, pval in props.items():
if "__" not in pname:
raise ValueError(
"Pipeline.fit does not accept the {} parameter. "
"You can pass parameters to specific steps of your "
"pipeline using the stepname__parameter format, e.g. "
"`Pipeline.fit(X, y, logisticregression__sample_weight"
"=sample_weight)`.".format(pname)
)
step, param = pname.split("__", 1)
per_step[step]["fit"][param] = pval
per_step[step]["fit_transform"][param] = pval
per_step[step]["fit_predict"][param] = pval
return _manual_routing(per_step)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is just de-indentation of the above code, since we do early-return anyway.

@StefanieSenger StefanieSenger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, looks good to me. Thank you, @adrinjalali.
I have a few nit comments only.

Comment on lines +1749 to +1750
contain keys for the metadata which should be routed to them. Consumers should
use item access (``routed_params[child][method]``) rather than attribute access,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
contain keys for the metadata which should be routed to them. Consumers should
use item access (``routed_params[child][method]``) rather than attribute access,
contain keys for the metadata which should be routed to them. Consumers have to
use item access (``routed_params[child][method]``) as opposed to attribute access,

Use a bit stronger language.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they don't have to, we're being nice here since dask backend has a bug.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, you're thinking about third party estimators that are consumers here. I didn't see from that perspective, but I can now go along with it.

Inside scikit-learn, I think we should always use dict access, especially while implementing new consumers, like callbacks (FYI @FrancoisPgm).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use dict access in the metadata routing docs then?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah doing that in the docs makes sense. Bur here's also the fix on joblib side: joblib/joblib#1798

method_mapping=MethodMapping().add(caller="fit", callee="fit"),
method_mapping=MethodMapping()
.add(caller="fit", callee="fit")
.add(caller="predict", callee="predict"),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

Comment thread sklearn/linear_model/_ransac.py Resolved
routed_params = _manual_routing(
{
name: {
"score": {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"score": {
"score": {
# **common_kwargs copies its keys and values into a new dict,
# so each scorer gets its own values

Let's add a comment indicating that common_kwargs gets copied. I was very surprised about that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they get the same values, they're not copied:

In [1]: a = [1]

In [2]: d1 = {1: a}

In [3]: d2 = {**d1, **{2: 3}}

In [4]: a.append(2)

In [5]: d1
Out[6]: {1: [1, 2]}

In [6]: d2
Out[7]: {1: [1, 2], 2: 3}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I see, the values (list a) can still change, because it is a shallow copy of common_kwargs.

I just wonder that we may not want to allow metadata to be able to change between metrics, probably not. We allowed it before though.

@StefanieSenger StefanieSenger added the Waiting for Second Reviewer First reviewer is done, need a second one! label Jun 8, 2026
@adrinjalali

Copy link
Copy Markdown
Member Author

@OmarManzoor this should be ready to merge now if you could review.

@OmarManzoor OmarManzoor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you @adrinjalali

@OmarManzoor
OmarManzoor merged commit da47f5c into scikit-learn:main Jun 9, 2026
33 checks passed
@adrinjalali
adrinjalali deleted the slep6/bunch branch June 10, 2026 08:07
prady0t pushed a commit to prady0t/scikit-learn that referenced this pull request Sep 2, 2026
@jeremiedbb jeremiedbb mentioned this pull request Sep 8, 2026
14 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Metadata Routing all issues related to metadata routing, slep006, sample props No Changelog Needed Waiting for Second Reviewer First reviewer is done, need a second one!

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Using dask distributed with a pipeline and column_transformer breaks metadata routing

3 participants