Failing FeatureUnion test with scikit-learn master
- Dominant language
- Python
- Stars
- 951
- Forks
- 262
- PR merge metrics
- No merged PRs in 30d
Description
`tests/model_selection/dask_searchcv/test_model_selection.py::test_feature_union` is failing with sklearn master.
Possibly related to https://github.com/scikit-learn/scikit-learn/issues/17355, but even when that's fixed by changing the `None` to `"drop"`, I still see failures.
```diff
diff --git a/tests/model_selection/dask_searchcv/test_model_selection.py b/tests/model_selection/dask_searchcv/test_model_selection.py
index 9e26e0d3..c4959979 100644
--- a/tests/model_selection/dask_searchcv/test_model_selection.py
+++ b/tests/model_selection/dask_searchcv/test_model_selection.py
@@ -509,7 +509,7 @@ def test_feature_union(weights):
p = {}
for n, c in enumerate(constants):
if c is None:
- p["tr%d" % n] = None
+ p["tr%d" % n] = "drop"
elif n == 3: # 3rd is always an estimator
p["tr%d" % n] = ScalingTransformer(c)
else:
```
```pytb
tests/model_selection/dask_searchcv/test_model_selection.py::test_feature_union[None] FAILED [ 50%]
======================================== FAILURES ========================================
________________________________ test_feature_union[None] ________________________________
weights = None
@pytest.mark.parametrize(
"weights", [None, (None, {"tr0": 2, "tr2": 3}, {"tr0": 2, "tr2": 4})]
)
def test_feature_union(weights):
X = np.ones((10, 5))
y = np.zeros(10)
union = FeatureUnion(
[
("tr0", ScalingTransformer()),
("tr1", ScalingTransformer()),
("tr2", ScalingTransformer()),
]
)
factors = [(2, 3, 5), (2, 4, 5), (2, 4, 6), (2, 4, None), (None, None, None)]
params, sols, grid = [], [], []
for constants, w in product(factors, weights or [None]):
p = {}
for n, c in enumerate(constants):
if c is None:
p["tr%d" % n] = "drop"
elif n == 3: # 3rd is always an estimator
p["tr%d" % n] = ScalingTransformer(c)
else:
p["tr%d__factor" % n] = c
sol = union.set_params(transformer_weights=w, **p).transform(X)
sols.append(sol)
if w is not None:
p["transformer_weights"] = w
params.append(p)
p2 = {"union__" + k: [v] for k, v in p.items()}
p2["est"] = [CheckXClassifier(sol[0])]
grid.append(p2)
# Need to recreate the union after setting estimators to `None` above
union = FeatureUnion(
[
("tr0", ScalingTransformer()),
("tr1", ScalingTransformer()),
("tr2", ScalingTransformer()),
]
)
pipe = Pipeline([("union", union), ("est", CheckXClassifier())])
gs = dcv.GridSearchCV(pipe, param_grid=grid, refit=False, cv=2, n_jobs=1)
> gs.fit(X, y)
tests/model_selection/dask_searchcv/test_model_selection.py:538:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
dask_ml/model_selection/_search.py:1271: in fit
out = scheduler(dsk, keys, num_workers=n_jobs)
../../Envs/dask-dev/lib/python3.7/site-packages/dask/local.py:527: in get_sync
return get_async(apply_sync, 1, dsk, keys, **kwargs)
../../Envs/dask-dev/lib/python3.7/site-packages/dask/local.py:494: in get_async
fire_task()
../../Envs/dask-dev/lib/python3.7/site-packages/dask/local.py:466: in fire_task
callback=queue.put,
../../Envs/dask-dev/lib/python3.7/site-packages/dask/local.py:516: in apply_sync
res = func(*args, **kwds)
../../Envs/dask-dev/lib/python3.7/site-packages/dask/local.py:227: in execute_task
result = pack_exception(e, dumps)
../../Envs/dask-dev/lib/python3.7/site-packages/dask/local.py:222: in execute_task
result = _execute_task(task, data)
../../Envs/dask-dev/lib/python3.7/site-packages/dask/core.py:121: in _execute_task
return func(*(_execute_task(a, cache) for a in args))
dask_ml/model_selection/methods.py:258: in fit_transform
est = set_params(est, fields, params)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
est = 'drop', fields = ['factor'], params = {}, copy = True
def set_params(est, fields=None, params=None, copy=True):
if copy:
est = copy_estimator(est)
if fields is None:
return est
params = {f: p for (f, p) in zip(fields, params) if p is not MISSING}
# TODO: rewrite set_params to avoid lock for classes that use the standard
# set_params/get_params methods
with SET_PARAMS_LOCK:
> return est.set_params(**params)
E AttributeError: 'str' object has no attribute 'set_params'
dask_ml/model_selection/methods.py:225: AttributeError
```
No time to work on this right now, so I'm xfailing that test.
Contributor guide
Assessment
This issue has not been assessed yet.