Skip to content

Commit

Permalink
Deprecating Series.argmin and Series.argmax (#16830)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Kushner committed Jul 15, 2017
1 parent 4c498f8 commit dfd9d06
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.21.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ Other API Changes
Deprecations
~~~~~~~~~~~~
- :func:`read_excel()` has deprecated ``sheetname`` in favor of ``sheet_name`` for consistency with ``.to_excel()`` (:issue:`10559`).
- :method:`Series.argmax` has been deprecated in favor of :method:`Series.idxmax` (:issue:`16830`)
- :method:`Series.argmin` has been deprecated in favor of :method:`Series.idxmin` (:issue:`16830`)


.. _whatsnew_0210.prior_deprecations:
Expand Down
7 changes: 4 additions & 3 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
import pandas.core.common as com
import pandas.core.nanops as nanops
import pandas.io.formats.format as fmt
from pandas.util._decorators import Appender, deprecate_kwarg, Substitution
from pandas.util._decorators import (
Appender, deprecate, deprecate_kwarg, Substitution)
from pandas.util._validators import validate_bool_kwarg

from pandas._libs import index as libindex, tslib as libts, lib, iNaT
Expand Down Expand Up @@ -1293,8 +1294,8 @@ def idxmax(self, axis=None, skipna=True, *args, **kwargs):
return self.index[i]

# ndarray compat
argmin = idxmin
argmax = idxmax
argmin = deprecate('argmin', idxmin)
argmax = deprecate('argmax', idxmax)

def round(self, decimals=0, *args, **kwargs):
"""
Expand Down
23 changes: 16 additions & 7 deletions pandas/tests/series/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1211,10 +1211,15 @@ def test_idxmin(self):
assert result == 1

def test_numpy_argmin(self):
# argmin is aliased to idxmin
data = np.random.randint(0, 11, size=10)
result = np.argmin(Series(data))
assert result == np.argmin(data)

with pytest.warns(FutureWarning):
result = np.argmin(Series(data))
assert result == np.argmin(data)

with tm.assert_produces_warning(FutureWarning):
# argmin is aliased to idxmin
Series(data).argmin()

if not _np_version_under1p10:
msg = "the 'out' parameter is not supported"
Expand Down Expand Up @@ -1266,11 +1271,15 @@ def test_idxmax(self):
assert result == 1.1

def test_numpy_argmax(self):

# argmax is aliased to idxmax
data = np.random.randint(0, 11, size=10)
result = np.argmax(Series(data))
assert result == np.argmax(data)

with pytest.warns(FutureWarning):
result = np.argmax(Series(data))
assert result == np.argmax(data)

with tm.assert_produces_warning(FutureWarning):
# argmax is aliased to idxmax
Series(data).argmax()

if not _np_version_under1p10:
msg = "the 'out' parameter is not supported"
Expand Down

0 comments on commit dfd9d06

Please sign in to comment.