Skip to content

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

Merged
merged 2 commits into from
Jan 19, 2021

Conversation

rhshadrach
Copy link
Member

@rhshadrach rhshadrach added Bug Apply Apply, Aggregate, Transform, Map labels Jan 16, 2021
@simonjayhawkins simonjayhawkins added this to the 1.3 milestone Jan 17, 2021
@@ -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)]
)
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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

Copy link
Member Author

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?

Copy link
Contributor

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

@jreback jreback merged commit 626448d into pandas-dev:master Jan 19, 2021
@jreback
Copy link
Contributor

jreback commented Jan 19, 2021

thanks @rhshadrach pls create an issue (or PR!) for re-orging the apply tests :->

@rhshadrach rhshadrach deleted the apply_str_raise_invalid_axis branch January 21, 2021 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform, Map Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: DataFrame.apply axis=1 for str ops with no axis argument
4 participants