From 29520681b37a419d42554d8686fd01f7de745008 Mon Sep 17 00:00:00 2001 From: Evan Wright Date: Thu, 14 May 2015 06:35:10 -0400 Subject: [PATCH] BUG: get_group fails when multi-grouping with a categorical (GH #10068) --- doc/source/whatsnew/v0.16.2.txt | 4 +++- pandas/core/index.py | 4 ++++ pandas/tests/test_groupby.py | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.16.2.txt b/doc/source/whatsnew/v0.16.2.txt index f1c5b0c854055..f5c9d15de65f6 100644 --- a/doc/source/whatsnew/v0.16.2.txt +++ b/doc/source/whatsnew/v0.16.2.txt @@ -68,7 +68,9 @@ Bug Fixes - Bug in getting timezone data with ``dateutil`` on various platforms ( :issue:`9059`, :issue:`8639`, :issue:`9663`, :issue:`10121`) - Bug in display datetimes with mixed frequencies uniformly; display 'ms' datetimes to the proper precision. (:issue:`10170`) -- Bung in ``Series`` arithmetic methods may incorrectly hold names (:issue:`10068`) +- Bug in ``Series`` arithmetic methods may incorrectly hold names (:issue:`10068`) + +- Bug in ``GroupBy.get_group`` when grouping on multiple keys, one of which is categorical. (:issue:`10132`) - Bug in ``DatetimeIndex`` and ``TimedeltaIndex`` names are lost after timedelta arithmetics ( :issue:`9926`) diff --git a/pandas/core/index.py b/pandas/core/index.py index 2bd96fcec2e42..1483ca9a47b46 100644 --- a/pandas/core/index.py +++ b/pandas/core/index.py @@ -2964,6 +2964,10 @@ def values(self): """ return the underlying data, which is a Categorical """ return self._data + def get_values(self): + """ return the underlying data as an ndarray """ + return self._data.get_values() + @property def codes(self): return self._data.codes diff --git a/pandas/tests/test_groupby.py b/pandas/tests/test_groupby.py index 0789e20df3945..a13922acfb3f0 100644 --- a/pandas/tests/test_groupby.py +++ b/pandas/tests/test_groupby.py @@ -5140,6 +5140,13 @@ def test_groupby_categorical_two_columns(self): "ints": [1,2,1,2,1,2]}).set_index(["cat","ints"]) tm.assert_frame_equal(res, exp) + # GH 10132 + for key in [('a', 1), ('b', 2), ('b', 1), ('a', 2)]: + c, i = key + result = groups_double_key.get_group(key) + expected = test[(test.cat == c) & (test.ints == i)] + assert_frame_equal(result, expected) + d = {'C1': [3, 3, 4, 5], 'C2': [1, 2, 3, 4], 'C3': [10, 100, 200, 34]} test = pd.DataFrame(d) values = pd.cut(test['C1'], [1, 2, 3, 6])