diff --git a/RELEASE.rst b/RELEASE.rst index 3173d9d58aa81..ae242af65e986 100644 --- a/RELEASE.rst +++ b/RELEASE.rst @@ -34,6 +34,8 @@ pandas 0.8.2 **Bug fixes** - Fix MM-YYYY time series indexing case (#1672) + - Fix case where Categorical group key was not being passed into index in + GroupBy result (#1701) pandas 0.8.1 ============ diff --git a/pandas/core/groupby.py b/pandas/core/groupby.py index 673e3b5d7ac11..6ed4e9aa822b9 100644 --- a/pandas/core/groupby.py +++ b/pandas/core/groupby.py @@ -1289,7 +1289,8 @@ def _get_index(): if isinstance(values[0], dict): # # GH #823 - return DataFrame(values, index=keys).stack() + index = _get_index() + return DataFrame(values, index=index).stack() if isinstance(values[0], (Series, dict)): return self._concat_objects(keys, values, diff --git a/pandas/tests/test_groupby.py b/pandas/tests/test_groupby.py index 2786f28b685f5..ad0b76c45e4b9 100644 --- a/pandas/tests/test_groupby.py +++ b/pandas/tests/test_groupby.py @@ -1426,6 +1426,17 @@ def test_apply_corner(self): expected = self.tsframe * 2 assert_frame_equal(result, expected) + def test_apply_use_categorical_name(self): + from pandas import qcut + cats = qcut(self.df.C, 4) + + def get_stats(group): + return {'min': group.min(), 'max': group.max(), + 'count': group.count(), 'mean': group.mean()} + + result = self.df.groupby(cats).D.apply(get_stats) + self.assertEquals(result.index.names[0], 'C') + def test_transform_mixed_type(self): index = MultiIndex.from_arrays([[0, 0, 0, 1, 1, 1], [1, 2, 3, 1, 2, 3]])