Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pandas/tests/apply/test_frame_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

# GH 35517
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.