Skip to content

Commit

Permalink
Deprecate numeric_only
Browse files Browse the repository at this point in the history
  • Loading branch information
Arno Veenstra committed Feb 14, 2019
1 parent 3169ac4 commit cf95e34
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
6 changes: 4 additions & 2 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2179,7 +2179,8 @@ def _reduce(self, name, axis=0, **kwargs):
raise TypeError(msg.format(op=name))
return func(**kwargs)

def min(self, skipna=True, **kwargs):
@deprecate_kwarg(old_arg_name='numeric_only', new_arg_name='skipna')
def min(self, skipna=True, numeric_only=None, **kwargs):
"""
The minimum value of the object.
Expand All @@ -2205,7 +2206,8 @@ def min(self, skipna=True, **kwargs):
else:
return self.categories[pointer]

def max(self, skipna=True, **kwargs):
@deprecate_kwarg(old_arg_name='numeric_only', new_arg_name='skipna')
def max(self, skipna=True, numeric_only=None, **kwargs):
"""
The maximum value of the object.
Expand Down
13 changes: 11 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3674,8 +3674,17 @@ def _reduce(self, op, name, axis=0, skipna=True, numeric_only=None,
if axis is not None:
self._get_axis_number(axis)

# dispatch to ExtensionArray interface
if isinstance(delegate, ExtensionArray):
if isinstance(delegate, Categorical):
# TODO: remove numeric_only argument and treat Categorical the same
# as all ExtensionArrays
# See https://github.com/pandas-dev/pandas/issues/25303
if numeric_only is not None:
return delegate._reduce(name, numeric_only=numeric_only,
**kwds)
else:
return delegate._reduce(name, skipna=skipna, **kwds)
elif isinstance(delegate, ExtensionArray):
# dispatch to ExtensionArray interface
return delegate._reduce(name, skipna=skipna, **kwds)
elif is_datetime64_dtype(delegate):
# use DatetimeIndex implementation to handle skipna correctly
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/reductions/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,12 @@ def test_min_max(self):
assert _min == "b"
assert _max == "c"

with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
_min = cat.min(numeric_only=False)
_max = cat.max(numeric_only=False)
assert np.isnan(_min)
assert _max == "c"


class TestSeriesMode(object):
# Note: the name TestSeriesMode indicates these tests
Expand Down

0 comments on commit cf95e34

Please sign in to comment.