Skip to content

Commit 500c76b

Browse files
committed
ENH: use Series name in GroupBy for result index, GH #363
1 parent 51f4e02 commit 500c76b

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

RELEASE.rst

+4-3
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ pandas 0.5.1
100100
- Can pass multiple levels to `stack` and `unstack` (GH #370)
101101
- Can pass multiple values columns to `pivot_table` (GH #381)
102102
- Can call `DataFrame.delevel` with standard Index with name set (GH #393)
103+
- Use Series name in GroupBy for result index (GH #363)
103104

104105
**Bug fixes**
105106

@@ -568,8 +569,8 @@ Thanks
568569
- Dan Lovell
569570
- Nick Pentreath
570571

571-
pandas 0.4
572-
==========
572+
pandas 0.4.0
573+
============
573574

574575
Release notes
575576
-------------
@@ -700,7 +701,7 @@ Release notes
700701
`DataFrame.count` to enable this behavior in those methods if so desired
701702
(disabled by default)
702703
* `DataFrame.pivot` generalized to enable pivoting multiple columns into a
703-
`DataFrame` with hierarhical columns
704+
`DataFrame` with hierarchical columns
704705
* `DataFrame` constructor can accept structured / record arrays
705706
* `Panel` constructor can accept a dict of DataFrame-like objects. Do not
706707
need to use `from_dict` anymore (`from_dict` is there to stay, though).

pandas/core/groupby.py

+4
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,10 @@ def __init__(self, index, grouper=None, name=None, level=None):
534534
self.grouper = _convert_grouper(index, grouper)
535535
self.index = index
536536

537+
# right place for this?
538+
if isinstance(grouper, Series) and name is None:
539+
self.name = grouper.name
540+
537541
if level is not None:
538542
if not isinstance(level, int):
539543
assert(level in index.names)

pandas/tests/test_groupby.py

+13
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,19 @@ def test_groupby_wrong_multi_labels(self):
10131013
expected = grouped.mean()
10141014
assert_frame_equal(result, expected)
10151015

1016+
def test_groupby_series_with_name(self):
1017+
result = self.df.groupby(self.df['A']).mean()
1018+
result2 = self.df.groupby(self.df['A'], as_index=False).mean()
1019+
self.assertEquals(result.index.name, 'A')
1020+
self.assert_('A' in result2)
1021+
1022+
result = self.df.groupby([self.df['A'], self.df['B']]).mean()
1023+
result2 = self.df.groupby([self.df['A'], self.df['B']],
1024+
as_index=False).mean()
1025+
self.assertEquals(result.index.names, ['A', 'B'])
1026+
self.assert_('A' in result2)
1027+
self.assert_('B' in result2)
1028+
10161029
class TestPanelGroupBy(unittest.TestCase):
10171030

10181031
def setUp(self):

0 commit comments

Comments
 (0)