Skip to content

Commit

Permalink
BUG: fix groupby.apply index name bug, close #1701
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Jul 30, 2012
1 parent f5a74d4 commit eec8a83
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions RELEASE.rst
Expand Up @@ -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
============
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/groupby.py
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/test_groupby.py
Expand Up @@ -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]])
Expand Down

0 comments on commit eec8a83

Please sign in to comment.