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 4 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]})
Copy link
Member

Choose a reason for hiding this comment

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

Please call df for consistency and create expected = df.copy() before applying where

Copy link
Member

Choose a reason for hiding this comment

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

Please create expected before calling where.

result = d1.where(pd.notnull(d1), None)
# make sure dtypes don't change
expected = d1
tm.assert_frame_equal(expected, result)