Skip to content

Commit a488ab8

Browse files
alimcmaster1jreback
authored andcommitted
TST: tests for categorical apply (#25095)
1 parent a814ea4 commit a488ab8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pandas/tests/series/test_apply.py

+12
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,18 @@ def test_apply_dict_depr(self):
163163
with tm.assert_produces_warning(FutureWarning):
164164
tsdf.A.agg({'foo': ['sum', 'mean']})
165165

166+
@pytest.mark.parametrize('series', [
167+
['1-1', '1-1', np.NaN],
168+
['1-1', '1-2', np.NaN]])
169+
def test_apply_categorical_with_nan_values(self, series):
170+
# GH 20714 bug fixed in: GH 24275
171+
s = pd.Series(series, dtype='category')
172+
result = s.apply(lambda x: x.split('-')[0])
173+
result = result.astype(object)
174+
expected = pd.Series(['1', '1', np.NaN], dtype='category')
175+
expected = expected.astype(object)
176+
tm.assert_series_equal(result, expected)
177+
166178

167179
class TestSeriesAggregate():
168180

0 commit comments

Comments
 (0)