-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fixed NDFrame.transform('abs') #20800
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
import pytest | ||
|
||
import operator | ||
from datetime import datetime | ||
|
||
import warnings | ||
|
@@ -880,11 +881,14 @@ def f(): | |
with np.errstate(all='ignore'): | ||
df.agg({'A': ['abs', 'sum'], 'B': ['mean', 'max']}) | ||
|
||
def test_transform_abs_name(self): | ||
@pytest.mark.parametrize('method', [ | ||
'abs', 'shift', 'pct_change', 'cumsum', 'rank', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could also add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Splitting to #20821 |
||
]) | ||
def test_transform_method_name(self, method): | ||
# https://github.com/pandas-dev/pandas/issues/19760 | ||
df = pd.DataFrame({"A": [-1, 2]}) | ||
result = df.transform('abs') | ||
expected = pd.DataFrame({"A": [1, 2]}) | ||
result = df.transform(method) | ||
expected = operator.methodcaller(method)(df) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Learned something new today. Just out of curiosity, is this any different from doing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in this case, no. methodcaller is nicer though when you need to bind parameters, but don't have the object yet (common in pytest fixtures). |
||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_demo(self): | ||
|
There was a problem hiding this comment.
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