Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0bf2479

Browse files
cmarmoMicky774ogrisel
authored
FIX Fix ranking for scipy >= 1.10. (#24483)
Co-authored-by: Meekail Zain <[email protected]> Co-authored-by: Olivier Grisel <[email protected]>
1 parent ac665ad commit 0bf2479

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

sklearn/model_selection/_search.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -965,11 +965,12 @@ def _store(key_name, array, weights=None, splits=False, rank=False):
965965
results["std_%s" % key_name] = array_stds
966966

967967
if rank:
968-
rank_result = rankdata(-array_means, method="min")
969968
# when input is nan, scipy >= 1.10 rankdata returns nan. To
970-
# keep previous behaviour nans are set to the
971-
# maximum possible rank
972-
rank_result[np.isnan(rank_result)] = len(rank_result)
969+
# keep previous behaviour nans are set to be smaller than the
970+
# minimum value in the array before ranking
971+
min_array_means = min(array_means) - 1
972+
array_means = np.nan_to_num(array_means, copy=True, nan=min_array_means)
973+
rank_result = rankdata(-array_means, method="min")
973974
rank_result = np.asarray(rank_result, dtype=np.int32)
974975
results["rank_%s" % key_name] = rank_result
975976

0 commit comments

Comments
 (0)