Skip to content

Commit

Permalink
Inconsistent handling of duplicate axes + mixed dtypes in DataFrame.w…
Browse files Browse the repository at this point in the history
  • Loading branch information
mitlabence authored Feb 26, 2022
1 parent 40e63c4 commit c3abb52
Showing 1 changed file with 16 additions and 0 deletions.
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

0 comments on commit c3abb52

Please sign in to comment.