Skip to content

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

Merged
merged 6 commits into from
Mar 7, 2022

Conversation

weikhor
Copy link
Contributor

@weikhor weikhor commented Mar 2, 2022

df = DataFrame([["foo"]])
result = type(df.apply(lambda col: np.array("bar")).iloc[0])
expected = np.ndarray
assert result == expected
Copy link
Contributor

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

Copy link
Contributor Author

@weikhor weikhor Mar 5, 2022

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.

Copy link
Member

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

Copy link
Contributor Author

@weikhor weikhor Mar 6, 2022

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():
Copy link
Contributor

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

Copy link
Contributor Author

@weikhor weikhor Mar 5, 2022

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

@jreback jreback added Apply Apply, Aggregate, Transform, Map Testing pandas testing functions or related to the test suite labels Mar 4, 2022
@jreback jreback added this to the 1.5 milestone Mar 4, 2022
def test_frame_apply_np_array_return_type(self):
# GH 35517
df = DataFrame([["foo"]])
df = df.apply(lambda col: np.array("bar")).iloc[0]
Copy link
Contributor

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

@mroeschke mroeschke merged commit 12f0b6a into pandas-dev:main Mar 7, 2022
@mroeschke
Copy link
Member

Thanks again @weikhor

@weikhor weikhor deleted the test_dataframe_apply branch May 31, 2022 16:11
yehoshuadimarsky pushed a commit to yehoshuadimarsky/pandas that referenced this pull request Jul 13, 2022
…e fn returns np.ndarray (pandas-dev#46199)

* Update test_frame_apply.py

* add

* relocate test case

* relocate test case

* remove iloc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform, Map Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Pandas 1.0.5 → 1.1.0 behavior change on DataFrame.apply() where fn returns np.ndarray
3 participants