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 4db0492

Browse filesBrowse files
jjerphanglemaitrelestevebetatim
authored
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 f965fcc commit 4db0492
Copy full SHA for 4db0492

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
@@ -3297,18 +3296,25 @@ def param_filter(p):
32973296
tuple,
32983297
type(None),
32993298
type,
3300-
types.FunctionType,
3301-
joblib.Memory,
33023299
}
33033300
# Any numpy numeric such as np.int32.
33043301
allowed_types.update(np.core.numerictypes.allTypes.values())
3305-
assert type(init_param.default) in allowed_types, (
3302+
3303+
allowed_value = (
3304+
type(init_param.default) in allowed_types
3305+
or
3306+
# Although callables are mutable, we accept them as argument
3307+
# default value and trust that neither the implementation of
3308+
# the callable nor of the estimator changes the state of the
3309+
# callable.
3310+
callable(init_param.default)
3311+
)
3312+
3313+
assert allowed_value, (
33063314
f"Parameter '{init_param.name}' of estimator "
33073315
f"'{Estimator.__name__}' is of type "
3308-
f"{type(init_param.default).__name__} which is not "
3309-
"allowed. All init parameters have to be immutable to "
3310-
"make cloning possible. Therefore we restrict the set of "
3311-
"legal types to "
3316+
f"{type(init_param.default).__name__} which is not allowed. "
3317+
f"'{init_param.name}' must be a callable or must be of type "
33123318
f"{set(type.__name__ for type in allowed_types)}."
33133319
)
33143320
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.