Skip to content

Inconsistent handling of duplicate axes + mixed dtypes in DataFrame.where #25399 #46139

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 3 commits into from
Feb 26, 2022
Merged
Changes from all 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
16 changes: 16 additions & 0 deletions pandas/tests/frame/indexing/test_where.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pandas import (
DataFrame,
DatetimeIndex,
Index,
Series,
StringDtype,
Timestamp,
Expand Down Expand Up @@ -863,6 +864,21 @@ def test_where_none_nan_coerce():
tm.assert_frame_equal(result, expected)


def test_where_duplicate_axes_mixed_dtypes():
# GH 25399, verify manually masking is not affected anymore by dtype of column for
# duplicate axes.
result = DataFrame(data=[[0, np.nan]], columns=Index(["A", "A"]))
index, columns = result.axes
mask = DataFrame(data=[[True, True]], columns=columns, index=index)
a = result.astype(object).where(mask)
b = result.astype("f8").where(mask)
c = result.T.where(mask.T).T
d = result.where(mask) # used to fail with "cannot reindex from a duplicate axis"
tm.assert_frame_equal(a.astype("f8"), b.astype("f8"))
tm.assert_frame_equal(b.astype("f8"), c.astype("f8"))
tm.assert_frame_equal(c.astype("f8"), d.astype("f8"))


def test_where_non_keyword_deprecation(frame_or_series):
# GH 41485
obj = frame_or_series(range(5))
Expand Down