Skip to content

Commit 7cc0dea

Browse files
committed
Do not mask infinite values in nanops.nanargmin, argmax (pandas-dev#13595)
The implementations of `nanargmin` and `nanargmax` in `nanops` were forcing the `_get_values` utility function to always mask out infinite values. For example, in `nanargmax`, >>> nanops._get_values(np.array([1, np.nan, np.inf]), True, isfinite=True, fill_value_typ='-inf') (array([ 1., -inf, -inf]), array([False, True, True], dtype=bool), dtype('float64'), numpy.float64) The first element of the result tuple (the masked version of the values array) is used for actually finding the max or min argument. As a result, infinite values could never be correctly recognized as the maximum or minimum values in an array.
1 parent 49ec31b commit 7cc0dea

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

pandas/core/nanops.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,7 @@ def nanargmax(values, axis=None, skipna=True):
474474
"""
475475
Returns -1 in the NA case
476476
"""
477-
values, mask, dtype, _ = _get_values(values, skipna, fill_value_typ='-inf',
478-
isfinite=True)
477+
values, mask, dtype, _ = _get_values(values, skipna, fill_value_typ='-inf')
479478
result = values.argmax(axis)
480479
result = _maybe_arg_null_out(result, axis, mask, skipna)
481480
return result
@@ -485,8 +484,7 @@ def nanargmin(values, axis=None, skipna=True):
485484
"""
486485
Returns -1 in the NA case
487486
"""
488-
values, mask, dtype, _ = _get_values(values, skipna, fill_value_typ='+inf',
489-
isfinite=True)
487+
values, mask, dtype, _ = _get_values(values, skipna, fill_value_typ='+inf')
490488
result = values.argmin(axis)
491489
result = _maybe_arg_null_out(result, axis, mask, skipna)
492490
return result

0 commit comments

Comments
 (0)