Skip to content

Commit 08b1511

Browse files
committed
Merge pull request #10132 from evanpw/cat_multigroup
BUG: get_group fails when multi-grouping with a categorical
2 parents 282746a + 2952068 commit 08b1511

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
@@ -73,7 +73,9 @@ Bug Fixes
7373
- Bug in getting timezone data with ``dateutil`` on various platforms ( :issue:`9059`, :issue:`8639`, :issue:`9663`, :issue:`10121`)
7474
- Bug in display datetimes with mixed frequencies uniformly; display 'ms' datetimes to the proper precision. (:issue:`10170`)
7575

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

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

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
@@ -5169,6 +5169,13 @@ def test_groupby_categorical_two_columns(self):
51695169
"ints": [1,2,1,2,1,2]}).set_index(["cat","ints"])
51705170
tm.assert_frame_equal(res, exp)
51715171

5172+
# GH 10132
5173+
for key in [('a', 1), ('b', 2), ('b', 1), ('a', 2)]:
5174+
c, i = key
5175+
result = groups_double_key.get_group(key)
5176+
expected = test[(test.cat == c) & (test.ints == i)]
5177+
assert_frame_equal(result, expected)
5178+
51725179
d = {'C1': [3, 3, 4, 5], 'C2': [1, 2, 3, 4], 'C3': [10, 100, 200, 34]}
51735180
test = pd.DataFrame(d)
51745181
values = pd.cut(test['C1'], [1, 2, 3, 6])

0 commit comments

Comments
 (0)