@@ -1086,36 +1086,33 @@ def _store(key_name, array, weights=None, splits=False, rank=False):
1086
1086
for key , param_result in param_results .items ():
1087
1087
param_list = list (param_result .values ())
1088
1088
try :
1089
- with warnings .catch_warnings ():
1090
- warnings .filterwarnings (
1091
- "ignore" ,
1092
- message = "in the future the `.dtype` attribute" ,
1093
- category = DeprecationWarning ,
1094
- )
1095
- # Warning raised by NumPy 1.20+
1096
- arr_dtype = np .result_type (* param_list )
1089
+ arr = np .array (param_list )
1097
1090
except (TypeError , ValueError ):
1098
1091
arr_dtype = np .dtype (object )
1099
1092
else :
1100
- if any (np .min_scalar_type (x ) == object for x in param_list ):
1101
- # `np.result_type` might get thrown off by `.dtype` properties
1102
- # (which some estimators have).
1103
- # If finding the result dtype this way would give object,
1104
- # then we use object.
1105
- # https://github.com/scikit-learn/scikit-learn/issues/29157
1106
- arr_dtype = np .dtype (object )
1107
- if len (param_list ) == n_candidates and arr_dtype != object :
1108
- # Exclude `object` else the numpy constructor might infer a list of
1109
- # tuples to be a 2d array.
1110
- results [key ] = MaskedArray (param_list , mask = False , dtype = arr_dtype )
1111
- else :
1112
- # Use one MaskedArray and mask all the places where the param is not
1113
- # applicable for that candidate (which may not contain all the params).
1114
- ma = MaskedArray (np .empty (n_candidates ), mask = True , dtype = arr_dtype )
1115
- for index , value in param_result .items ():
1116
- # Setting the value at an index unmasks that index
1117
- ma [index ] = value
1118
- results [key ] = ma
1093
+ arr_dtype = arr .dtype if (arr .dtype .kind != "U" ) else object
1094
+ if len (param_list ) == n_candidates :
1095
+ try :
1096
+ ma = MaskedArray (param_list , mask = False , dtype = arr_dtype )
1097
+ except ValueError :
1098
+ # Fall back to iterating over `param_result.items()` below
1099
+ pass
1100
+ else :
1101
+ if ma .ndim > 1 :
1102
+ # If ndim > 1, then a list of tuples might be turned into
1103
+ # a 2D array, so we use the fallback below for that case too.
1104
+ arr_dtype = object
1105
+ else :
1106
+ results [key ] = ma
1107
+ continue
1108
+
1109
+ # Use one MaskedArray and mask all the places where the param is not
1110
+ # applicable for that candidate (which may not contain all the params).
1111
+ ma = MaskedArray (np .empty (n_candidates ), mask = True , dtype = arr_dtype )
1112
+ for index , value in param_result .items ():
1113
+ # Setting the value at an index unmasks that index
1114
+ ma [index ] = value
1115
+ results [key ] = ma
1119
1116
1120
1117
# Store a list of param dicts at the key 'params'
1121
1118
results ["params" ] = candidate_params
0 commit comments