Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Fixed NDFrame.transform('abs') #20800

Merged
merged 3 commits into from
Apr 25, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ def get_result(self):

# string dispatch
if isinstance(self.f, compat.string_types):
self.kwds['axis'] = self.axis
if self.f not in {'abs'}:
Copy link
Contributor

Choose a reason for hiding this comment

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

NO, anytime 'hacky' work-around you need to re-think the patch.

Copy link
Contributor

Choose a reason for hiding this comment

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

either you need signature introspection (in python 3, may not be possible in python 2), alternatively can catch this type of error, but should be much higher level (in .aggregate), and not here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ugh, signature introspection seems hackier than hard-coding, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll see how hard it is to get Py2 & 3 working by inspecting the signature.

# Not all transform functions take an axis keyword.
self.kwds['axis'] = self.axis
return getattr(self.obj, self.f)(*self.args, **self.kwds)

# 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