Skip to content

Commit ac58f24

Browse files
author
Arno Veenstra
committed
Change default value and fix test
1 parent ab9f597 commit ac58f24

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

pandas/core/arrays/categorical.py

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

2182-
def min(self, skipna=None, **kwargs):
2182+
def min(self, skipna=True, **kwargs):
21832183
"""
21842184
The minimum value of the object.
21852185
@@ -2205,7 +2205,7 @@ def min(self, skipna=None, **kwargs):
22052205
else:
22062206
return self.categories[pointer]
22072207

2208-
def max(self, skipna=None, **kwargs):
2208+
def max(self, skipna=True, **kwargs):
22092209
"""
22102210
The maximum value of the object.
22112211

pandas/tests/arrays/categorical/test_analytics.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_min_max(self):
3838
categories=['d', 'c', 'b', 'a'], ordered=True)
3939
_min = cat.min()
4040
_max = cat.max()
41-
assert np.isnan(_min)
41+
assert _min == "c"
4242
assert _max == "b"
4343

4444
_min = cat.min(numeric_only=True)
@@ -48,8 +48,8 @@ def test_min_max(self):
4848

4949
cat = Categorical([np.nan, 1, 2, np.nan], categories=[5, 4, 3, 2, 1],
5050
ordered=True)
51-
_min = cat.min()
52-
_max = cat.max()
51+
_min = cat.min(skipna=False)
52+
_max = cat.max(skipna=False)
5353
assert np.isnan(_min)
5454
assert _max == 1
5555

pandas/tests/reductions/test_reductions.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -948,18 +948,25 @@ def test_min_max(self):
948948
cat = Series(Categorical(
949949
[np.nan, "b", "c", np.nan], categories=['d', 'c', 'b', 'a'
950950
], ordered=True))
951-
_min = cat.min()
952-
_max = cat.max()
951+
_min = cat.min(skipna=False)
952+
_max = cat.max(skipna=False)
953953
assert np.isnan(_min)
954954
assert _max == "b"
955955

956956
cat = Series(Categorical(
957957
[np.nan, 1, 2, np.nan], categories=[5, 4, 3, 2, 1], ordered=True))
958958
_min = cat.min()
959959
_max = cat.max()
960-
assert np.isnan(_min)
960+
assert _min == 2
961961
assert _max == 1
962962

963+
cat = Series(Categorical(
964+
["a", "b", "c", "a"], categories=["b", "c", "d"], ordered=True))
965+
_min = cat.min()
966+
_max = cat.max()
967+
assert _min == "b"
968+
assert _max == "c"
969+
963970

964971
class TestSeriesMode(object):
965972
# Note: the name TestSeriesMode indicates these tests

pandas/tests/series/test_analytics.py

-8
Original file line numberDiff line numberDiff line change
@@ -1497,11 +1497,3 @@ def test_drop_duplicates_categorical_bool(self, is_ordered):
14971497
sc = tc.copy()
14981498
sc.drop_duplicates(keep=False, inplace=True)
14991499
tm.assert_series_equal(sc, tc[~expected])
1500-
1501-
def test_min_skipna(self):
1502-
raw_cat = pd.Categorical(["a", "b", "c", "a"],
1503-
categories=["b", "c", "d"],
1504-
ordered=True)
1505-
s = pd.Series(raw_cat)
1506-
result = s.min(skipna=True)
1507-
assert result == 'b'

0 commit comments

Comments
 (0)