Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,11 @@ def get_result(self):

# string dispatch
if isinstance(self.f, compat.string_types):
self.kwds['axis'] = self.axis
return getattr(self.obj, self.f)(*self.args, **self.kwds)
func = getattr(self.obj, self.f)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much better, and now IIRC we actually do something like this in groupby apply (for the same reason). can you add some comments here on what is going on

sig = compat.signature(func)
if 'axis' in sig.args:
self.kwds['axis'] = self.axis
return func(*self.args, **self.kwds)

# ufunc
elif isinstance(self.f, np.ufunc):
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/frame/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,13 @@ def f():
with np.errstate(all='ignore'):
df.agg({'A': ['abs', 'sum'], 'B': ['mean', 'max']})

def test_transform_abs_name(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need more tests? (for other funcs)

# https://github.com/pandas-dev/pandas/issues/19760
df = pd.DataFrame({"A": [-1, 2]})
result = df.transform('abs')
expected = pd.DataFrame({"A": [1, 2]})
tm.assert_frame_equal(result, expected)

def test_demo(self):
# demonstration tests
df = pd.DataFrame({'A': range(5), 'B': 5})
Expand Down