-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: DataFrame.apply axis=1 for str ops with no axis argument #39212
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: DataFrame.apply axis=1 for str ops with no axis argument #39212
Conversation
rhshadrach
commented
Jan 16, 2021
- closes BUG: DataFrame.apply axis=1 for str ops with no axis argument #39211
- tests added / passed
- Ensure all linting tests pass, see here for how to run them
- whatsnew entry
@@ -179,6 +179,16 @@ def test_apply_with_string_funcs(self, request, float_frame, func, args, kwds, h | |||
expected = getattr(float_frame, func)(*args, **kwds) | |||
tm.assert_series_equal(result, expected) | |||
|
|||
@pytest.mark.parametrize( | |||
"how, args", [("pct_change", ()), ("nsmallest", (1, ["a", "b"])), ("tail", 1)] | |||
) |
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.
does this already raise when a function is passed? ideally can you co-locate these tests.
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.
When function is passed, apply with axis=1 computes the correct result. E.g.
df = DataFrame([[1, 2, 3], [4, 5, 6]])
print(df.apply(lambda x: x.tail(1), axis=1))
# gives:
2
0 3
1 6
The argument axis=1
is intercepted and then apply_standard
is computed on the rows of the frame without an axis argument.
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.
ok cool, can you co-locate this test near the others
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.
What is meant by others? Currently located below the other test for str arguments. Tests for axis=1 and tests that raise are fairly spread out in this file, not sure how else to locate this test.
As an aside, I've been wanting to consolidate (and then start to cleanup) the apply/agg/transform tests into pandas.tests.apply
. Does that move make sense?
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.
ok cool
yeah would love to break up some of these test files more logically
thanks @rhshadrach pls create an issue (or PR!) for re-orging the apply tests :-> |