Skip to content

Commit 81c07d2

Browse files
Lucas KushnerLucas Kushner
Lucas Kushner
authored and
Lucas Kushner
committed
Deprecating Series.argmin and Series.argmax (pandas-dev#16830)
1 parent 4c498f8 commit 81c07d2

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
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+
- :func:`Series.argmax` has been deprecated in favor of :func:`Series.idxmax` (:issue:`16830`)
120+
- :func:`Series.argmin` has been deprecated in favor of :func:`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

+24-9
Original file line numberDiff line numberDiff line change
@@ -1210,11 +1210,19 @@ def test_idxmin(self):
12101210
result = s.idxmin()
12111211
assert result == 1
12121212

1213-
def test_numpy_argmin(self):
1214-
# argmin is aliased to idxmin
1213+
def test_numpy_argmin_deprecated(self):
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+
# The deprecation of Series.argmin also causes a deprecation warning
1218+
# when calling np.argmin
1219+
result = np.argmin(Series(data))
1220+
assert result == np.argmin(data)
1221+
1222+
with tm.assert_produces_warning(FutureWarning):
1223+
# argmin is aliased to idxmin
1224+
result = Series(data).argmin()
1225+
assert result == Series(data).idxmin()
12181226

12191227
if not _np_version_under1p10:
12201228
msg = "the 'out' parameter is not supported"
@@ -1265,12 +1273,19 @@ def test_idxmax(self):
12651273
result = s.idxmin()
12661274
assert result == 1.1
12671275

1268-
def test_numpy_argmax(self):
1269-
1270-
# argmax is aliased to idxmax
1276+
def test_numpy_argmax_deprecated(self):
12711277
data = np.random.randint(0, 11, size=10)
1272-
result = np.argmax(Series(data))
1273-
assert result == np.argmax(data)
1278+
1279+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
1280+
# The deprecation of Series.argmax also causes a deprecation warning
1281+
# when calling np.argmax
1282+
result = np.argmax(Series(data))
1283+
assert result == np.argmax(data)
1284+
1285+
with tm.assert_produces_warning(FutureWarning):
1286+
# argmax is aliased to idxmax
1287+
result = Series(data).argmax()
1288+
assert result == Series(data).idxmax()
12741289

12751290
if not _np_version_under1p10:
12761291
msg = "the 'out' parameter is not supported"

0 commit comments

Comments
 (0)