Skip to content

Commit

Permalink
Do not mask infinite values in nanops.nanargmin, argmax (pandas-dev#1…
Browse files Browse the repository at this point in the history
…3595)

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.
  • Loading branch information
DGrady committed May 23, 2017
1 parent 49ec31b commit 7cc0dea
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,7 @@ def nanargmax(values, axis=None, skipna=True):
"""
Returns -1 in the NA case
"""
values, mask, dtype, _ = _get_values(values, skipna, fill_value_typ='-inf',
isfinite=True)
values, mask, dtype, _ = _get_values(values, skipna, fill_value_typ='-inf')
result = values.argmax(axis)
result = _maybe_arg_null_out(result, axis, mask, skipna)
return result
Expand All @@ -485,8 +484,7 @@ def nanargmin(values, axis=None, skipna=True):
"""
Returns -1 in the NA case
"""
values, mask, dtype, _ = _get_values(values, skipna, fill_value_typ='+inf',
isfinite=True)
values, mask, dtype, _ = _get_values(values, skipna, fill_value_typ='+inf')
result = values.argmin(axis)
result = _maybe_arg_null_out(result, axis, mask, skipna)
return result
Expand Down

0 comments on commit 7cc0dea

Please sign in to comment.