From f1b5c30646a4f2b81744d64dfabdcdcc80c1430a Mon Sep 17 00:00:00 2001 From: alimcmaster1 Date: Sat, 2 Feb 2019 18:25:20 +0000 Subject: [PATCH 1/2] Add tests for categorical apply --- pandas/tests/series/test_apply.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pandas/tests/series/test_apply.py b/pandas/tests/series/test_apply.py index 90cf6916df0d1..23a7a6a1823c7 100644 --- a/pandas/tests/series/test_apply.py +++ b/pandas/tests/series/test_apply.py @@ -163,6 +163,17 @@ def test_apply_dict_depr(self): with tm.assert_produces_warning(FutureWarning): tsdf.A.agg({'foo': ['sum', 'mean']}) + @pytest.mark.parametrize('series', [ + ['1-1', '1-1', np.NaN], + ['1-1', '1-2', np.NaN]]) + def test_apply_categorical_with_nan_values(self, series): + # GH 20714 + s = pd.Series(series, dtype='category') + result = s.apply(lambda x: x.split('-')[0]) + expected = pd.Series(['1', '1', np.NaN], dtype='category') + tm.assert_series_equal(result.astype(object), + expected.astype(object), check_dtype=False) + class TestSeriesAggregate(): From 48f7f08410d9890673695d2c2771f1d03138e125 Mon Sep 17 00:00:00 2001 From: alimcmaster1 Date: Sat, 2 Feb 2019 23:14:41 +0000 Subject: [PATCH 2/2] Add tests for categorical apply --- pandas/tests/series/test_apply.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/tests/series/test_apply.py b/pandas/tests/series/test_apply.py index 23a7a6a1823c7..162a27db34cb1 100644 --- a/pandas/tests/series/test_apply.py +++ b/pandas/tests/series/test_apply.py @@ -167,12 +167,13 @@ def test_apply_dict_depr(self): ['1-1', '1-1', np.NaN], ['1-1', '1-2', np.NaN]]) def test_apply_categorical_with_nan_values(self, series): - # GH 20714 + # GH 20714 bug fixed in: GH 24275 s = pd.Series(series, dtype='category') result = s.apply(lambda x: x.split('-')[0]) + result = result.astype(object) expected = pd.Series(['1', '1', np.NaN], dtype='category') - tm.assert_series_equal(result.astype(object), - expected.astype(object), check_dtype=False) + expected = expected.astype(object) + tm.assert_series_equal(result, expected) class TestSeriesAggregate():