From dfd9d06aba2cf3794d3f2349133828c5b3db34a8 Mon Sep 17 00:00:00 2001 From: Lucas Kushner Date: Sat, 15 Jul 2017 19:28:56 +0000 Subject: [PATCH] Deprecating Series.argmin and Series.argmax (#16830) --- doc/source/whatsnew/v0.21.0.txt | 2 ++ pandas/core/series.py | 7 ++++--- pandas/tests/series/test_analytics.py | 23 ++++++++++++++++------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index 6ddf6029b99bb..993c35dce7bac 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -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: diff --git a/pandas/core/series.py b/pandas/core/series.py index e1f668dd3afda..5294031be0ff8 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -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 @@ -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): """ diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 749af1c56a7f0..fa95e0027ef3a 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -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" @@ -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"