Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e5ac79d

Browse filesBrowse files
jjerphanglemaitrelestevebetatim
authored andcommitted
TST Allow callables as valid parameter regarding cloning estimator (#25498)
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com> Co-authored-by: Loïc Estève <loic.esteve@ymail.com> Co-authored-by: From: Tim Head <betatim@gmail.com>
1 parent e5f0316 commit e5ac79d
Copy full SHA for e5ac79d

File tree

1 file changed

+14
-8
lines changed
Filter options

1 file changed

+14
-8
lines changed

‎sklearn/utils/estimator_checks.py

Copy file name to clipboardExpand all lines: sklearn/utils/estimator_checks.py
+14-8Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import types
21
import warnings
32
import pickle
43
import re
@@ -3277,18 +3276,25 @@ def param_filter(p):
32773276
tuple,
32783277
type(None),
32793278
type,
3280-
types.FunctionType,
3281-
joblib.Memory,
32823279
}
32833280
# Any numpy numeric such as np.int32.
32843281
allowed_types.update(np.core.numerictypes.allTypes.values())
3285-
assert type(init_param.default) in allowed_types, (
3282+
3283+
allowed_value = (
3284+
type(init_param.default) in allowed_types
3285+
or
3286+
# Although callables are mutable, we accept them as argument
3287+
# default value and trust that neither the implementation of
3288+
# the callable nor of the estimator changes the state of the
3289+
# callable.
3290+
callable(init_param.default)
3291+
)
3292+
3293+
assert allowed_value, (
32863294
f"Parameter '{init_param.name}' of estimator "
32873295
f"'{Estimator.__name__}' is of type "
3288-
f"{type(init_param.default).__name__} which is not "
3289-
"allowed. All init parameters have to be immutable to "
3290-
"make cloning possible. Therefore we restrict the set of "
3291-
"legal types to "
3296+
f"{type(init_param.default).__name__} which is not allowed. "
3297+
f"'{init_param.name}' must be a callable or must be of type "
32923298
f"{set(type.__name__ for type in allowed_types)}."
32933299
)
32943300
if init_param.name not in params.keys():

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.