Skip to content

Commit 9d57dc8

Browse files
committed
BUG: Fix GH15155
1 parent 684c4d5 commit 9d57dc8

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

pandas/indexes/category.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ def categories(self):
255255
def ordered(self):
256256
return self._data.ordered
257257

258+
def _reverse_indexer(self):
259+
return self._data._reverse_indexer()
260+
258261
def __contains__(self, key):
259262
hash(key)
260263
return key in self.values

pandas/tests/groupby/test_categorical.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
from pandas.core.series import Series
1111

12-
from pandas.util.testing import (assert_frame_equal, assert_series_equal
13-
)
12+
from pandas.util.testing import (assert_frame_equal, assert_series_equal,
13+
assert_numpy_array_equal)
1414

1515
from pandas.compat import (lmap)
1616

@@ -48,8 +48,9 @@ def setUp(self):
4848
'D': np.array(
4949
np.random.randn(8), dtype='float32')})
5050

51-
index = MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'], ['one', 'two',
52-
'three']],
51+
index = MultiIndex(levels=[pd.CategoricalIndex(
52+
['foo', 'bar', 'baz', 'qux']),
53+
['one', 'two', 'three']],
5354
labels=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],
5455
[0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
5556
names=['first', 'second'])
@@ -67,6 +68,12 @@ def setUp(self):
6768
'E': np.random.randn(11),
6869
'F': np.random.randn(11)})
6970

71+
def test_level_groupby_get_group(self):
72+
# gh15155
73+
testGroupBy = self.mframe.groupby(level=["first"])
74+
assert_numpy_array_equal(testGroupBy.get_group("foo").values,
75+
self.mframe.loc["foo"].values)
76+
7077
def test_apply_use_categorical_name(self):
7178
from pandas import qcut
7279
cats = qcut(self.df.C, 4)

0 commit comments

Comments
 (0)