File tree 1 file changed +14
-8
lines changed
Filter options
1 file changed +14
-8
lines changed
Original file line number Diff line number Diff line change 1
- import types
2
1
import warnings
3
2
import pickle
4
3
import re
@@ -3277,18 +3276,25 @@ def param_filter(p):
3277
3276
tuple ,
3278
3277
type (None ),
3279
3278
type ,
3280
- types .FunctionType ,
3281
- joblib .Memory ,
3282
3279
}
3283
3280
# Any numpy numeric such as np.int32.
3284
3281
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 , (
3286
3294
f"Parameter '{ init_param .name } ' of estimator "
3287
3295
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 "
3292
3298
f"{ set (type .__name__ for type in allowed_types )} ."
3293
3299
)
3294
3300
if init_param .name not in params .keys ():
You can’t perform that action at this time.
0 commit comments