Skip to content

Commit bb9b601

Browse files
committed
TST: add test to cover bug GH pandas-dev#14580
Add test to verify type of returned value of iloc() Series of Categorical data.
1 parent 9a69ca5 commit bb9b601

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pandas/tests/test_categorical.py

+21
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,27 @@ def test_getitem_listlike(self):
5454
expected = c[np.array([100000]).astype(np.int64)].codes
5555
self.assert_numpy_array_equal(result, expected)
5656

57+
def test_getitem_category_type(self):
58+
# GH 14580
59+
# test iloc() on Series with Categorical data
60+
61+
s = pd.Series([1, 2, 3]).astype('category')
62+
63+
# get slice
64+
result = s.iloc[0:2]
65+
expected = pd.Series([1, 2]).astype('category', categories=[1, 2, 3])
66+
tm.assert_series_equal(result, expected)
67+
68+
# get list of indexes
69+
result = s.iloc[[0, 1]]
70+
expected = pd.Series([1, 2]).astype('category', categories=[1, 2, 3])
71+
tm.assert_series_equal(result, expected)
72+
73+
# get boolean array
74+
result = s.iloc[[True, False, False]]
75+
expected = pd.Series([1]).astype('category', categories=[1, 2, 3])
76+
tm.assert_series_equal(result, expected)
77+
5778
def test_setitem(self):
5879

5980
# int/positional

0 commit comments

Comments
 (0)