Skip to content

Commit

Permalink
Change default value and fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Arno Veenstra committed Feb 13, 2019
1 parent ab9f597 commit ac58f24
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2179,7 +2179,7 @@ def _reduce(self, name, axis=0, **kwargs):
raise TypeError(msg.format(op=name))
return func(**kwargs)

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

def max(self, skipna=None, **kwargs):
def max(self, skipna=True, **kwargs):
"""
The maximum value of the object.
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/arrays/categorical/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_min_max(self):
categories=['d', 'c', 'b', 'a'], ordered=True)
_min = cat.min()
_max = cat.max()
assert np.isnan(_min)
assert _min == "c"
assert _max == "b"

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

cat = Categorical([np.nan, 1, 2, np.nan], categories=[5, 4, 3, 2, 1],
ordered=True)
_min = cat.min()
_max = cat.max()
_min = cat.min(skipna=False)
_max = cat.max(skipna=False)
assert np.isnan(_min)
assert _max == 1

Expand Down
13 changes: 10 additions & 3 deletions pandas/tests/reductions/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,18 +948,25 @@ def test_min_max(self):
cat = Series(Categorical(
[np.nan, "b", "c", np.nan], categories=['d', 'c', 'b', 'a'
], ordered=True))
_min = cat.min()
_max = cat.max()
_min = cat.min(skipna=False)
_max = cat.max(skipna=False)
assert np.isnan(_min)
assert _max == "b"

cat = Series(Categorical(
[np.nan, 1, 2, np.nan], categories=[5, 4, 3, 2, 1], ordered=True))
_min = cat.min()
_max = cat.max()
assert np.isnan(_min)
assert _min == 2
assert _max == 1

cat = Series(Categorical(
["a", "b", "c", "a"], categories=["b", "c", "d"], ordered=True))
_min = cat.min()
_max = cat.max()
assert _min == "b"
assert _max == "c"


class TestSeriesMode(object):
# Note: the name TestSeriesMode indicates these tests
Expand Down
8 changes: 0 additions & 8 deletions pandas/tests/series/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1497,11 +1497,3 @@ def test_drop_duplicates_categorical_bool(self, is_ordered):
sc = tc.copy()
sc.drop_duplicates(keep=False, inplace=True)
tm.assert_series_equal(sc, tc[~expected])

def test_min_skipna(self):
raw_cat = pd.Categorical(["a", "b", "c", "a"],
categories=["b", "c", "d"],
ordered=True)
s = pd.Series(raw_cat)
result = s.min(skipna=True)
assert result == 'b'

0 comments on commit ac58f24

Please sign in to comment.