Skip to content

Commit 1ce4d7d

Browse files
committed
BUG: get_group fails when multi-grouping with a categorical (GH #10068)
1 parent 676cb95 commit 1ce4d7d

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

doc/source/whatsnew/v0.16.2.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ Bug Fixes
6666
- Bug in getting timezone data with ``dateutil`` on various platforms ( :issue:`9059`, :issue:`8639`, :issue:`9663`, :issue:`10121`)
6767
- Bug in display datetimes with mixed frequencies uniformly; display 'ms' datetimes to the proper precision. (:issue:`10170`)
6868

69-
- Bung in ``Series`` arithmetic methods may incorrectly hold names (:issue:`10068`)
69+
- Bug in ``Series`` arithmetic methods may incorrectly hold names (:issue:`10068`)
70+
71+
- Bug in ``GroupBy.get_group`` when grouping on multiple keys, one of which is categorical. (:issue:`10132`)
7072

7173
- Bug in ``DatetimeIndex`` and ``TimedeltaIndex`` names are lost after timedelta arithmetics ( :issue:`9926`)
7274

pandas/core/index.py

+4
Original file line numberDiff line numberDiff line change
@@ -2964,6 +2964,10 @@ def values(self):
29642964
""" return the underlying data, which is a Categorical """
29652965
return self._data
29662966

2967+
def get_values(self):
2968+
""" return the underlying data as an ndarray """
2969+
return self._data.get_values()
2970+
29672971
@property
29682972
def codes(self):
29692973
return self._data.codes

pandas/tests/test_groupby.py

+7
Original file line numberDiff line numberDiff line change
@@ -5140,6 +5140,13 @@ def test_groupby_categorical_two_columns(self):
51405140
"ints": [1,2,1,2,1,2]}).set_index(["cat","ints"])
51415141
tm.assert_frame_equal(res, exp)
51425142

5143+
# GH 10132
5144+
for key in [('a', 1), ('b', 2), ('b', 1), ('a', 2)]:
5145+
c, i = key
5146+
result = groups_double_key.get_group(key)
5147+
expected = test[(test.cat == c) & (test.ints == i)]
5148+
assert_frame_equal(result, expected)
5149+
51435150
d = {'C1': [3, 3, 4, 5], 'C2': [1, 2, 3, 4], 'C3': [10, 100, 200, 34]}
51445151
test = pd.DataFrame(d)
51455152
values = pd.cut(test['C1'], [1, 2, 3, 6])

0 commit comments

Comments
 (0)