From b37b52225955d3dbf13faaa127cd9e49860fe1f6 Mon Sep 17 00:00:00 2001 From: Arno Veenstra Date: Wed, 13 Feb 2019 19:49:11 +0100 Subject: [PATCH] Change default value and fix test --- pandas/core/arrays/categorical.py | 4 ++-- .../tests/arrays/categorical/test_analytics.py | 16 ++++++++-------- pandas/tests/reductions/test_reductions.py | 13 ++++++++++--- pandas/tests/series/test_analytics.py | 8 -------- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index d4a8521eb3cbff..d9e77e9a362f83 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -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. @@ -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. diff --git a/pandas/tests/arrays/categorical/test_analytics.py b/pandas/tests/arrays/categorical/test_analytics.py index 5efcd527de8d82..fc8bfda9f3b4e5 100644 --- a/pandas/tests/arrays/categorical/test_analytics.py +++ b/pandas/tests/arrays/categorical/test_analytics.py @@ -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", [ diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index 173f719edd4655..0df880a41fe59e 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -948,8 +948,8 @@ 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" @@ -957,9 +957,16 @@ def test_min_max(self): [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 diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index c8b9dcfee956a1..6811e370726b29 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -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'