Skip to content

Commit

Permalink
BUG: honor column selection in GroupBy.transform on DataFrame, close #…
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Jun 2, 2012
1 parent 7cfb226 commit 0d3c3ec
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ pandas 0.8.0
error (#1090)
- Consistently set name on groupby pieces (#184)
- Treat dict return values as Series in GroupBy.apply (#823)
- Respect column selection for DataFrame in in GroupBy.transform (#1365)

pandas 0.7.3
============
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,9 @@ def transform(self, func, *args, **kwargs):
applied = []

obj = self._obj_with_exclusions
for name, group in self:
gen = self.grouper.get_iterator(obj, axis=self.axis)

for name, group in gen:
object.__setattr__(group, 'name', name)

try:
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,16 @@ def test_dispatch_transform(self):
expected = df.groupby(lambda x: x.month).transform(fillit)
assert_frame_equal(filled, expected)

def test_transform_select_columns(self):
f = lambda x: x.mean()
result = self.df.groupby('A')['C', 'D'].transform(f)

selection = self.df[['C', 'D']]
expected = selection.groupby(self.df['A']).transform(f)

assert_frame_equal(result, expected)


def test_with_na(self):
index = Index(np.arange(10))
values = Series(np.ones(10), index)
Expand Down

0 comments on commit 0d3c3ec

Please sign in to comment.