Skip to content

Commit cf95e34

Browse files
author
Arno Veenstra
committed
Deprecate numeric_only
1 parent 3169ac4 commit cf95e34

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

pandas/core/arrays/categorical.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2179,7 +2179,8 @@ def _reduce(self, name, axis=0, **kwargs):
21792179
raise TypeError(msg.format(op=name))
21802180
return func(**kwargs)
21812181

2182-
def min(self, skipna=True, **kwargs):
2182+
@deprecate_kwarg(old_arg_name='numeric_only', new_arg_name='skipna')
2183+
def min(self, skipna=True, numeric_only=None, **kwargs):
21832184
"""
21842185
The minimum value of the object.
21852186
@@ -2205,7 +2206,8 @@ def min(self, skipna=True, **kwargs):
22052206
else:
22062207
return self.categories[pointer]
22072208

2208-
def max(self, skipna=True, **kwargs):
2209+
@deprecate_kwarg(old_arg_name='numeric_only', new_arg_name='skipna')
2210+
def max(self, skipna=True, numeric_only=None, **kwargs):
22092211
"""
22102212
The maximum value of the object.
22112213

pandas/core/series.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -3674,8 +3674,17 @@ def _reduce(self, op, name, axis=0, skipna=True, numeric_only=None,
36743674
if axis is not None:
36753675
self._get_axis_number(axis)
36763676

3677-
# dispatch to ExtensionArray interface
3678-
if isinstance(delegate, ExtensionArray):
3677+
if isinstance(delegate, Categorical):
3678+
# TODO: remove numeric_only argument and treat Categorical the same
3679+
# as all ExtensionArrays
3680+
# See https://github.com/pandas-dev/pandas/issues/25303
3681+
if numeric_only is not None:
3682+
return delegate._reduce(name, numeric_only=numeric_only,
3683+
**kwds)
3684+
else:
3685+
return delegate._reduce(name, skipna=skipna, **kwds)
3686+
elif isinstance(delegate, ExtensionArray):
3687+
# dispatch to ExtensionArray interface
36793688
return delegate._reduce(name, skipna=skipna, **kwds)
36803689
elif is_datetime64_dtype(delegate):
36813690
# use DatetimeIndex implementation to handle skipna correctly

pandas/tests/reductions/test_reductions.py

+6
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,12 @@ def test_min_max(self):
967967
assert _min == "b"
968968
assert _max == "c"
969969

970+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
971+
_min = cat.min(numeric_only=False)
972+
_max = cat.max(numeric_only=False)
973+
assert np.isnan(_min)
974+
assert _max == "c"
975+
970976

971977
class TestSeriesMode(object):
972978
# Note: the name TestSeriesMode indicates these tests

0 commit comments

Comments
 (0)