Repository navigation
Description
Describe the bug and give evidence about its user-facing impact
when using a pipeline with a columns transformer, using the pipeline in a distributed environment seems to raise a strange error.
Steps/Code to Reproduce
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.compose import make_column_transformer
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import OneHotEncoder
from sklearn.preprocessing import StandardScaler, QuantileTransformer
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import cross_val_score
X, y = make_classification()
pipeline = make_pipeline(
make_column_transformer(
(StandardScaler(), [0]),
),
# StandardScaler(),
RandomForestClassifier(
max_depth=7, n_estimators=300, random_state=42
)
)
pipeline
cv_results = cross_val_score(pipeline, X, y, cv=5, n_jobs=1)
print("CV score:", np.mean(cv_results))
from distributed import Client
from joblib import parallel_config
client = Client()
with parallel_config("dask"):
cv_scores = cross_val_score(pipeline, X, y, cv=5, n_jobs=-1)
print("CV score:", np.mean(cv_scores))
client.close()Expected Results
CV score: 0.8300000000000001
CV score: 0.8300000000000001
Actual Results
CV score: 0.8300000000000001
warnings.warn(
/home/tom/Work/prog/scikit-learn/sklearn/model_selection/_validation.py:944: UserWarning: Scoring failed. The score on this train-test partition for these parameters will be set to nan. Details:
joblib.externals.loky.process_executor._RemoteTraceback:
"""
Traceback (most recent call last):
File "/home/tom/Work/prog/joblib/joblib/_utils.py", line 109, in call
return self.func(**kwargs)
^^^^^^^^^^^^^^^^^^^
File "/home/tom/Work/prog/joblib/joblib/_dask.py", line 128, in call
results.append(func(*args, **kwargs))
^^^^^^^^^^^^^^^^^^^^^
File "/home/tom/Work/prog/scikit-learn/sklearn/utils/parallel.py", line 184, in call
return self.function(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tom/Work/prog/scikit-learn/sklearn/pipeline.py", line 1486, in _transform_one
res = transformer.transform(X, **params.transform)
^^^^^^^^^^^^^^^^
AttributeError: 'dict' object has no attribute 'transform'
"""
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/tom/Work/prog/scikit-learn/sklearn/metrics/_scorer.py", line 170, in call
score = scorer(estimator, *args, **routed_params.get(name).score)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tom/Work/prog/scikit-learn/sklearn/metrics/_scorer.py", line 485, in call
return estimator.score(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tom/Work/prog/scikit-learn/sklearn/pipeline.py", line 1138, in score
Xt = transform.transform(Xt)
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tom/Work/prog/scikit-learn/sklearn/utils/_set_output.py", line 334, in wrapped
data_to_wrap = f(self, X, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tom/Work/prog/scikit-learn/sklearn/compose/_column_transformer.py", line 1079, in transform
Xs = self._call_func_on_transformers(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tom/Work/prog/scikit-learn/sklearn/compose/_column_transformer.py", line 889, in _call_func_on_transformers
return Parallel(n_jobs=self.n_jobs)(jobs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tom/Work/prog/scikit-learn/sklearn/utils/parallel.py", line 91, in call
return super().call(iterable_with_config_and_warning_filters)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tom/Work/prog/joblib/joblib/parallel.py", line 2094, in call
return output if self.return_generator else list(output)
^^^^^^^^^^^^
File "/home/tom/Work/prog/joblib/joblib/parallel.py", line 1704, in _get_outputs
yield from self._retrieve()
File "/home/tom/Work/prog/joblib/joblib/parallel.py", line 1806, in _retrieve
self._raise_error_fast()
File "/home/tom/Work/prog/joblib/joblib/parallel.py", line 1881, in _raise_error_fast
error_job.get_result(self.timeout)
File "/home/tom/Work/prog/joblib/joblib/parallel.py", line 780, in get_result
return self._return_or_raise()
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tom/Work/prog/joblib/joblib/parallel.py", line 795, in _return_or_raise
raise self._result
AttributeError: 'dict' object has no attribute 'transform'
[...] x 5
CV score: nan
Versions
1.8.0/1.9.dev0Interest in fixing the bug
If times allow it.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
tomMoral commentedon May 12, 2026
Note that changing backend to
lokyfixes the behavior.Also, not using the column transformer (just the standard scaler) also remove the error.
this probably comes from a bad deserialization of the params as a dict instead of a
Bunchbut it is unclear why it only happens fordask.adrinjalali commentedon May 20, 2026
This is the root of the cause, which is not idea, since it's ignoring the child classes of
dict:and
daskbackend uses this. We can fix it in sklearn by not using the bunch syntax, but I think the issue needs to be fixed on the dask backend side. WDYT?StefanieSenger commentedon Jun 8, 2026
I am not sure if I can reproduce. Running the reproducer on main returns:
(Note these values are different.)
Though I had do use
client = Client(n_workers=2, threads_per_worker=1, memory_limit="2GB")and
n_jobs=2instead of
client = Client()and
n_jobs=-1Otherwise my computer breaks down. 😆
StefanieSenger commentedon Jun 8, 2026
Okay, the error is not stable. I ran it a few more times and could finally reproduce. 😅