Skip to content

Commit 06ac22d

Browse files
thomasjpfanjorisvandenbossche
authored andcommitted
BUG: Fixes _BaseCompostion._set_params broken where there are no estimators (scikit-learn#11333)
1 parent f42522c commit 06ac22d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

sklearn/compose/tests/test_column_transformer.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,11 @@ def test_column_transformer_no_estimators():
794794
assert ct.transformers_[-1][2] == [0, 1, 2]
795795

796796

797+
def test_column_transformer_no_estimators_set_params():
798+
ct = ColumnTransformer([]).set_params(n_jobs=2)
799+
assert ct.n_jobs == 2
800+
801+
797802
def test_column_transformer_callable_specifier():
798803
# assert that function gets the full array / dataframe
799804
X_array = np.array([[0, 1, 2], [2, 4, 6]]).T

sklearn/utils/metaestimators.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ def _set_params(self, attr, **params):
4141
if attr in params:
4242
setattr(self, attr, params.pop(attr))
4343
# 2. Step replacement
44-
names, _ = zip(*getattr(self, attr))
44+
items = getattr(self, attr)
45+
names = []
46+
if items:
47+
names, _ = zip(*items)
4548
for name in list(six.iterkeys(params)):
4649
if '__' not in name and name in names:
4750
self._replace_estimator(attr, name, params.pop(name))

0 commit comments

Comments
 (0)