diff --git a/pandas/tests/test_categorical.py b/pandas/tests/test_categorical.py index f01fff035a3c59..0dff8e8f452bae 100644 --- a/pandas/tests/test_categorical.py +++ b/pandas/tests/test_categorical.py @@ -54,6 +54,24 @@ def test_getitem_listlike(self): expected = c[np.array([100000]).astype(np.int64)].codes self.assert_numpy_array_equal(result, expected) + def test_getitem_category_type(self): + # GH 14580 + # test iloc() on Series with Categorical data + + s = pd.Series([1, 2, 3]).astype('category') + + # get slice + result = s.iloc[0:1] + self.assertEqual(type(result), type(s)) + + # get list of indexes + result = s.iloc[[0, 1]] + self.assertEqual(type(result), type(s)) + + # get boolean array + result = s.iloc[[True, False, False]] + self.assertEqual(type(result), type(s)) + def test_setitem(self): # int/positional