Skip to content

Commit

Permalink
Set skipna=None by default and add future warning
Browse files Browse the repository at this point in the history
  • Loading branch information
makbigc committed Nov 1, 2019
1 parent 765e506 commit 300a862
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
14 changes: 10 additions & 4 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2195,7 +2195,7 @@ def _reduce(self, name, axis=0, **kwargs):
return func(**kwargs)

@deprecate_kwarg(old_arg_name="numeric_only", new_arg_name="skipna")
def min(self, skipna=True, **kwargs):
def min(self, skipna=None, **kwargs):
"""
The minimum value of the object.
Expand All @@ -2212,17 +2212,20 @@ def min(self, skipna=True, **kwargs):
"""
self.check_for_ordered("min")
good = self._codes != -1
if good.any():
if not good.all():
if skipna:
pointer = self._codes[good].min(**kwargs)
else:
msg = ("The default value of skipna will be changed to "
"True in the future version.")
warn(msg, FutureWarning, stacklevel=2)
return np.nan
else:
pointer = self._codes.min(**kwargs)
return self.categories[pointer]

@deprecate_kwarg(old_arg_name="numeric_only", new_arg_name="skipna")
def max(self, skipna=True, **kwargs):
def max(self, skipna=None, **kwargs):
"""
The maximum value of the object.
Expand All @@ -2239,10 +2242,13 @@ def max(self, skipna=True, **kwargs):
"""
self.check_for_ordered("max")
good = self._codes != -1
if good.any():
if not good.all():
if skipna:
pointer = self._codes[good].max(**kwargs)
else:
msg = ("The default value of skipna will be changed to "
"True in the future version.")
warn(msg, FutureWarning, stacklevel=2)
return np.nan
else:
pointer = self._codes.max(**kwargs)
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/arrays/categorical/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ def test_deprecate_numeric_only_min_max(self, method):
cat = Categorical(
[np.nan, 1, 2, np.nan], categories=[5, 4, 3, 2, 1], ordered=True
)
with tm.assert_produces_warning(expected_warning=FutureWarning):
getattr(cat, method)(numeric_only=False)
with tm.assert_produces_warning(expected_warning=FutureWarning,
check_stacklevel=False):
getattr(cat, method)(numeric_only=True)

@pytest.mark.parametrize(
"values,categories,exp_mode",
Expand Down

0 comments on commit 300a862

Please sign in to comment.