Skip to content

Commit 26f76d5

Browse files
jbrockmendeljreback
authored andcommitted
DEPR: argmin (#30113)
1 parent 51bd049 commit 26f76d5

File tree

3 files changed

+23
-64
lines changed

3 files changed

+23
-64
lines changed

doc/source/whatsnew/v1.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
611611
- Changed the default ``fill_value`` in :meth:`Categorical.take` from ``True`` to ``False`` (:issue:`20841`)
612612
- Changed the default value for the `raw` argument in :func:`Series.rolling().apply() <pandas.core.window.Rolling.apply>`, :func:`DataFrame.rolling().apply() <pandas.core.window.Rolling.apply>`,
613613
- :func:`Series.expanding().apply() <pandas.core.window.Expanding.apply>`, and :func:`DataFrame.expanding().apply() <pandas.core.window.Expanding.apply>` to ``False`` (:issue:`20584`)
614+
- Removed deprecated behavior of :meth:`Series.argmin` and :meth:`Series.argmax`, use :meth:`Series.idxmin` and :meth:`Series.idxmax` for the old behavior (:issue:`16955`)
614615
- Passing a tz-aware ``datetime.datetime`` or :class:`Timestamp` into the :class:`Timestamp` constructor with the ``tz`` argument now raises a ``ValueError`` (:issue:`23621`)
615616
- Removed the previously deprecated :attr:`Series.base`, :attr:`Index.base`, :attr:`Categorical.base`, :attr:`Series.flags`, :attr:`Index.flags`, :attr:`PeriodArray.flags`, :attr:`Series.strides`, :attr:`Index.strides`, :attr:`Series.itemsize`, :attr:`Index.itemsize`, :attr:`Series.data`, :attr:`Index.data` (:issue:`20721`)
616617
- Changed :meth:`Timedelta.resolution` to match the behavior of the standard library ``datetime.timedelta.resolution``, for the old behavior, use :meth:`Timedelta.resolution_string` (:issue:`26839`)

pandas/core/series.py

+1-31
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from pandas._libs import index as libindex, lib, reshape, tslibs
1515
from pandas.compat.numpy import function as nv
16-
from pandas.util._decorators import Appender, Substitution, deprecate
16+
from pandas.util._decorators import Appender, Substitution
1717
from pandas.util._validators import validate_bool_kwarg, validate_percentile
1818

1919
from pandas.core.dtypes.common import (
@@ -2001,36 +2001,6 @@ def idxmax(self, axis=0, skipna=True, *args, **kwargs):
20012001
return np.nan
20022002
return self.index[i]
20032003

2004-
# ndarray compat
2005-
argmin = deprecate(
2006-
"argmin",
2007-
idxmin,
2008-
"0.21.0",
2009-
msg=dedent(
2010-
"""
2011-
The current behaviour of 'Series.argmin' is deprecated, use 'idxmin'
2012-
instead.
2013-
The behavior of 'argmin' will be corrected to return the positional
2014-
minimum in the future. For now, use 'series.values.argmin' or
2015-
'np.argmin(np.array(values))' to get the position of the minimum
2016-
row."""
2017-
),
2018-
)
2019-
argmax = deprecate(
2020-
"argmax",
2021-
idxmax,
2022-
"0.21.0",
2023-
msg=dedent(
2024-
"""
2025-
The current behaviour of 'Series.argmax' is deprecated, use 'idxmax'
2026-
instead.
2027-
The behavior of 'argmax' will be corrected to return the positional
2028-
maximum in the future. For now, use 'series.values.argmax' or
2029-
'np.argmax(np.array(values))' to get the position of the maximum
2030-
row."""
2031-
),
2032-
)
2033-
20342004
def round(self, decimals=0, *args, **kwargs):
20352005
"""
20362006
Round each value in a Series to the given number of decimals.

pandas/tests/reductions/test_reductions.py

+21-33
Original file line numberDiff line numberDiff line change
@@ -695,52 +695,40 @@ def test_empty_timeseries_reductions_return_nat(self):
695695
assert Series([], dtype=dtype).min(skipna=False) is pd.NaT
696696
assert Series([], dtype=dtype).max(skipna=False) is pd.NaT
697697

698-
def test_numpy_argmin_deprecated(self):
698+
def test_numpy_argmin(self):
699699
# See GH#16830
700700
data = np.arange(1, 11)
701701

702702
s = Series(data, index=data)
703-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
704-
# The deprecation of Series.argmin also causes a deprecation
705-
# warning when calling np.argmin. This behavior is temporary
706-
# until the implementation of Series.argmin is corrected.
707-
result = np.argmin(s)
703+
result = np.argmin(s)
708704

709-
assert result == 1
705+
expected = np.argmin(data)
706+
assert result == expected
710707

711-
with tm.assert_produces_warning(FutureWarning):
712-
# argmin is aliased to idxmin
713-
result = s.argmin()
708+
result = s.argmin()
714709

715-
assert result == 1
710+
assert result == expected
716711

717-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
718-
msg = "the 'out' parameter is not supported"
719-
with pytest.raises(ValueError, match=msg):
720-
np.argmin(s, out=data)
712+
msg = "the 'out' parameter is not supported"
713+
with pytest.raises(ValueError, match=msg):
714+
np.argmin(s, out=data)
721715

722-
def test_numpy_argmax_deprecated(self):
716+
def test_numpy_argmax(self):
723717
# See GH#16830
724718
data = np.arange(1, 11)
725719

726720
s = Series(data, index=data)
727-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
728-
# The deprecation of Series.argmax also causes a deprecation
729-
# warning when calling np.argmax. This behavior is temporary
730-
# until the implementation of Series.argmax is corrected.
731-
result = np.argmax(s)
732-
assert result == 10
733-
734-
with tm.assert_produces_warning(FutureWarning):
735-
# argmax is aliased to idxmax
736-
result = s.argmax()
737-
738-
assert result == 10
739-
740-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
741-
msg = "the 'out' parameter is not supported"
742-
with pytest.raises(ValueError, match=msg):
743-
np.argmax(s, out=data)
721+
result = np.argmax(s)
722+
expected = np.argmax(data)
723+
assert result == expected
724+
725+
result = s.argmax()
726+
727+
assert result == expected
728+
729+
msg = "the 'out' parameter is not supported"
730+
with pytest.raises(ValueError, match=msg):
731+
np.argmax(s, out=data)
744732

745733
def test_idxmin(self):
746734
# test idxmin

0 commit comments

Comments
 (0)