Skip to content

Commit 56e0117

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 41b77ca commit 56e0117

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pandas/tests/test_categorical.py

+18
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,24 @@ 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:1]
65+
self.assertEqual(type(result), type(s))
66+
67+
# get list of indexes
68+
result = s.iloc[[0, 1]]
69+
self.assertEqual(type(result), type(s))
70+
71+
# get boolean array
72+
result = s.iloc[[True, False, False]]
73+
self.assertEqual(type(result), type(s))
74+
5775
def test_setitem(self):
5876

5977
# int/positional

0 commit comments

Comments
 (0)