-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Test : Pandas 1.0.5 → 1.1.0 behavior change on DataFrame.apply() where fn returns np.ndarray #46199
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
Conversation
df = DataFrame([["foo"]]) | ||
result = type(df.apply(lambda col: np.array("bar")).iloc[0]) | ||
expected = np.ndarray | ||
assert result == expected |
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.
can you actually construct the expected exactly and use tm.assert_equal
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.
Hi. I think I cannot do it using tm.assert_equal. The expected is np.ndarray
type, not DataFrame
type.
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.
Could you assert the full result of df.apply(lambda col: np.array("bar"))
? Not including the the iloc[0]
part or type
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.
Yes. I have removed iloc[0] part. Using tm.assert_series_equal
in the test case.
@@ -1551,3 +1551,11 @@ def foo(x): | |||
df = DataFrame({"a": [1, 2, 3]}) | |||
with tm.assert_produces_warning(UserWarning, match="Hello, World!"): | |||
df.agg([foo]) | |||
|
|||
|
|||
def test_apply_return_type(): |
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.
there are other tests for return_type can you co-locate
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.
Have relocated the file to pandas/tests/frame/methods/test_dtypes.py
def test_frame_apply_np_array_return_type(self): | ||
# GH 35517 | ||
df = DataFrame([["foo"]]) | ||
df = df.apply(lambda col: np.array("bar")).iloc[0] |
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.
pls actually construct the expected value and use tm.assert_frame_equal
Thanks again @weikhor |
…e fn returns np.ndarray (pandas-dev#46199) * Update test_frame_apply.py * add * relocate test case * relocate test case * remove iloc
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.