Skip to content

Commit 2b7ebbc

Browse files
author
Lucas Kushner
committed
Deprecating Series.argmin and Series.argmax (#16830)
1 parent 4c498f8 commit 2b7ebbc

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

doc/source/whatsnew/v0.21.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ Other API Changes
116116
Deprecations
117117
~~~~~~~~~~~~
118118
- :func:`read_excel()` has deprecated ``sheetname`` in favor of ``sheet_name`` for consistency with ``.to_excel()`` (:issue:`10559`).
119+
- :method:`Series.argmax` has been deprecated in favor of :method:`Series.idxmax` (:issue:`16830`)
120+
- :method:`Series.argmin` has been deprecated in favor of :method:`Series.idxmin` (:issue:`16830`)
119121

120122

121123
.. _whatsnew_0210.prior_deprecations:

pandas/core/series.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
import pandas.core.common as com
7272
import pandas.core.nanops as nanops
7373
import pandas.io.formats.format as fmt
74-
from pandas.util._decorators import Appender, deprecate_kwarg, Substitution
74+
from pandas.util._decorators import (
75+
Appender, deprecate, deprecate_kwarg, Substitution)
7576
from pandas.util._validators import validate_bool_kwarg
7677

7778
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):
12931294
return self.index[i]
12941295

12951296
# ndarray compat
1296-
argmin = idxmin
1297-
argmax = idxmax
1297+
argmin = deprecate('argmin', idxmin)
1298+
argmax = deprecate('argmax', idxmax)
12981299

12991300
def round(self, decimals=0, *args, **kwargs):
13001301
"""

pandas/tests/series/test_analytics.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -1211,10 +1211,15 @@ def test_idxmin(self):
12111211
assert result == 1
12121212

12131213
def test_numpy_argmin(self):
1214-
# argmin is aliased to idxmin
12151214
data = np.random.randint(0, 11, size=10)
1216-
result = np.argmin(Series(data))
1217-
assert result == np.argmin(data)
1215+
1216+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
1217+
result = np.argmin(Series(data))
1218+
assert result == np.argmin(data)
1219+
1220+
with tm.assert_produces_warning(FutureWarning):
1221+
# argmin is aliased to idxmin
1222+
Series(data).argmin()
12181223

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

12681273
def test_numpy_argmax(self):
1269-
1270-
# argmax is aliased to idxmax
12711274
data = np.random.randint(0, 11, size=10)
1272-
result = np.argmax(Series(data))
1273-
assert result == np.argmax(data)
1275+
1276+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
1277+
result = np.argmax(Series(data))
1278+
assert result == np.argmax(data)
1279+
1280+
with tm.assert_produces_warning(FutureWarning):
1281+
# argmax is aliased to idxmax
1282+
Series(data).argmax()
12741283

12751284
if not _np_version_under1p10:
12761285
msg = "the 'out' parameter is not supported"

0 commit comments

Comments
 (0)