Skip to content
Open
Changes from 1 commit
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 @@ -1063,3 +1063,13 @@ def test_where_inplace_no_other():
assert result is df
expected = DataFrame({"a": [1, np.nan], "b": [np.nan, "y"]})
tm.assert_frame_equal(df, expected)


def test_where_other_nullable_dtype():
# GH#49052 DataFrame.where should return nullable dtype when
# other is a Series with nullable dtype, matching Series.where behavior
df = Series([1, 2, 3], dtype="int64").to_frame()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
df = Series([1, 2, 3], dtype="int64").to_frame()
df = DataFrame([1, 2, 3], dtype="int64")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thanks.

other = Series([pd.NA, pd.NA, pd.NA], dtype="Int64")
result = df.where(df > 1, other, axis=0)
expected = DataFrame({0: Series([pd.NA, 2, 3], dtype="Int64")})
tm.assert_frame_equal(result, expected)
Loading