Deprecating Series.argmin and Series.argmax (#16830) by lphk92 · Pull Request #16955 · pandas-dev/pandas (original) (raw)

Just to make sure this doesn't get lost, there's an issue with this current approach, as np.argmin(arr), etc. will dispatch to arr.argmin, which warns immediately.

In [1]: import pandas as pd; import numpy as np s = ^[[A In [2]: s = pd.Series([1, 2])

In [3]: s Out[3]: 0 1 1 2 dtype: int64

In [4]: np.argmin(s) /Users/taugspurger/Envs/pandas-dev/lib/python3.6/site-packages/numpy/core/fromnumeric.py:57: FutureWarning: argmin is deprecated. Use idxmin instead return getattr(obj, method)(*args, **kwds) Out[4]: 0

These functions do take *args and **kwargs, so we could slip in a __pandas__deprecated kwargs, to control whether or not to warn. Something like

diff --git a/pandas/core/series.py b/pandas/core/series.py index 5294031be..cfda05486 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1287,6 +1287,8 @@ class Series(base.IndexOpsMixin, strings.StringAccessorMixin, DataFrame.idxmax numpy.ndarray.argmax """

@@ -1294,7 +1296,10 @@ class Series(base.IndexOpsMixin, strings.StringAccessorMixin, return self.index[i]

 # ndarray compat

@lphk92 currently this fails in validate_kwargs in pandas/pandas/util/_validators.py, but you may be able to get it to work. Mind trying it out?