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 b37b522
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 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
16 changes: 8 additions & 8 deletions pandas/tests/arrays/categorical/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,26 @@ def test_min_max(self):

cat = 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"

_min = cat.min(numeric_only=True)
_min = cat.min()
assert _min == "c"
_max = cat.max(numeric_only=True)
_max = cat.max()
assert _max == "b"

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

_min = cat.min(numeric_only=True)
_min = cat.min()
assert _min == 2
_max = cat.max(numeric_only=True)
_max = cat.max()
assert _max == 1

@pytest.mark.parametrize("values,categories,exp_mode", [
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 b37b522

Please sign in to comment.