Skip to content

TST: Add testing to df.where() typecasting as per GH 42295 #43173

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
Aug 26, 2021
Merged
Changes from 2 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
10 changes: 10 additions & 0 deletions pandas/tests/frame/indexing/test_where.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,3 +771,13 @@ def test_where_non_keyword_deprecation():
result = s.where(s > 1, 10, False)
expected = DataFrame([10, 10, 2, 3, 4])
tm.assert_frame_equal(expected, result)


def test_where_columns_casting():
# GH 42295

d1 = DataFrame({"a": [1.0, 2.0], 'b': [3, np.nan]})
result = d1.where(pd.notnull(d1), None).dtypes
# make sure dtypes don't change
expected = d1.dtypes
tm.assert_series_equal(expected, result)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of comparing the .dtype results. Could you compare the DataFrame result of result of d1.where(pd.notnull(d1), None)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks for the review. I updated it.