Skip to content

Commit 300a862

Browse files
committed
Set skipna=None by default and add future warning
1 parent 765e506 commit 300a862

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

pandas/core/arrays/categorical.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,7 +2195,7 @@ def _reduce(self, name, axis=0, **kwargs):
21952195
return func(**kwargs)
21962196

21972197
@deprecate_kwarg(old_arg_name="numeric_only", new_arg_name="skipna")
2198-
def min(self, skipna=True, **kwargs):
2198+
def min(self, skipna=None, **kwargs):
21992199
"""
22002200
The minimum value of the object.
22012201
@@ -2212,17 +2212,20 @@ def min(self, skipna=True, **kwargs):
22122212
"""
22132213
self.check_for_ordered("min")
22142214
good = self._codes != -1
2215-
if good.any():
2215+
if not good.all():
22162216
if skipna:
22172217
pointer = self._codes[good].min(**kwargs)
22182218
else:
2219+
msg = ("The default value of skipna will be changed to "
2220+
"True in the future version.")
2221+
warn(msg, FutureWarning, stacklevel=2)
22192222
return np.nan
22202223
else:
22212224
pointer = self._codes.min(**kwargs)
22222225
return self.categories[pointer]
22232226

22242227
@deprecate_kwarg(old_arg_name="numeric_only", new_arg_name="skipna")
2225-
def max(self, skipna=True, **kwargs):
2228+
def max(self, skipna=None, **kwargs):
22262229
"""
22272230
The maximum value of the object.
22282231
@@ -2239,10 +2242,13 @@ def max(self, skipna=True, **kwargs):
22392242
"""
22402243
self.check_for_ordered("max")
22412244
good = self._codes != -1
2242-
if good.any():
2245+
if not good.all():
22432246
if skipna:
22442247
pointer = self._codes[good].max(**kwargs)
22452248
else:
2249+
msg = ("The default value of skipna will be changed to "
2250+
"True in the future version.")
2251+
warn(msg, FutureWarning, stacklevel=2)
22462252
return np.nan
22472253
else:
22482254
pointer = self._codes.max(**kwargs)

pandas/tests/arrays/categorical/test_analytics.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ def test_deprecate_numeric_only_min_max(self, method):
7070
cat = Categorical(
7171
[np.nan, 1, 2, np.nan], categories=[5, 4, 3, 2, 1], ordered=True
7272
)
73-
with tm.assert_produces_warning(expected_warning=FutureWarning):
74-
getattr(cat, method)(numeric_only=False)
73+
with tm.assert_produces_warning(expected_warning=FutureWarning,
74+
check_stacklevel=False):
75+
getattr(cat, method)(numeric_only=True)
7576

7677
@pytest.mark.parametrize(
7778
"values,categories,exp_mode",

0 commit comments

Comments
 (0)