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
@@ -3297,18 +3296,25 @@ def param_filter(p):
3297
3296
tuple ,
3298
3297
type (None ),
3299
3298
type ,
3300
- types .FunctionType ,
3301
- joblib .Memory ,
3302
3299
}
3303
3300
# Any numpy numeric such as np.int32.
3304
3301
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 , (
3306
3314
f"Parameter '{ init_param .name } ' of estimator "
3307
3315
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 "
3312
3318
f"{ set (type .__name__ for type in allowed_types )} ."
3313
3319
)
3314
3320
if init_param .name not in params .keys ():
You can’t perform that action at this time.
0 commit comments