@@ -2606,21 +2606,37 @@ def param_filter(p):
2606
2606
allowed_types .update ({
2607
2607
np .core .numerictypes .allTypes .values ()
2608
2608
})
2609
- assert type (init_param .default ) in allowed_types
2609
+ assert type (init_param .default ) in allowed_types , (
2610
+ f"Parameter '{ init_param .name } ' of estimator "
2611
+ f"'{ Estimator .__name__ } ' is of type "
2612
+ f"{ type (init_param .default ).__name__ } which is not "
2613
+ f"allowed. All init parameters have to be immutable to "
2614
+ f"make cloning possible. Therefore we restrict the set of "
2615
+ f"legal types to "
2616
+ f"{ set (type .__name__ for type in allowed_types )} ."
2617
+ )
2610
2618
if init_param .name not in params .keys ():
2611
2619
# deprecated parameter, not in get_params
2612
- assert init_param .default is None
2620
+ assert init_param .default is None , (
2621
+ f"Estimator parameter '{ init_param .name } ' of estimator "
2622
+ f"'{ Estimator .__name__ } ' is not returned by get_params. "
2623
+ f"If it is deprecated, set its default value to None."
2624
+ )
2613
2625
continue
2614
2626
2615
2627
param_value = params [init_param .name ]
2616
2628
if isinstance (param_value , np .ndarray ):
2617
2629
assert_array_equal (param_value , init_param .default )
2618
2630
else :
2631
+ failure_text = (
2632
+ f"Parameter { init_param .name } was mutated on init. All "
2633
+ f"parameters must be stored unchanged."
2634
+ )
2619
2635
if is_scalar_nan (param_value ):
2620
2636
# Allows to set default parameters to np.nan
2621
- assert param_value is init_param .default , init_param . name
2637
+ assert param_value is init_param .default , failure_text
2622
2638
else :
2623
- assert param_value == init_param .default , init_param . name
2639
+ assert param_value == init_param .default , failure_text
2624
2640
2625
2641
2626
2642
def _enforce_estimator_tags_y (estimator , y ):
0 commit comments