Skip to content

Commit c3abb52

Browse files
authored
Inconsistent handling of duplicate axes + mixed dtypes in DataFrame.where #25399 (#46139)
1 parent 40e63c4 commit c3abb52

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pandas/tests/frame/indexing/test_where.py

+16
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from pandas import (
1313
DataFrame,
1414
DatetimeIndex,
15+
Index,
1516
Series,
1617
StringDtype,
1718
Timestamp,
@@ -863,6 +864,21 @@ def test_where_none_nan_coerce():
863864
tm.assert_frame_equal(result, expected)
864865

865866

867+
def test_where_duplicate_axes_mixed_dtypes():
868+
# GH 25399, verify manually masking is not affected anymore by dtype of column for
869+
# duplicate axes.
870+
result = DataFrame(data=[[0, np.nan]], columns=Index(["A", "A"]))
871+
index, columns = result.axes
872+
mask = DataFrame(data=[[True, True]], columns=columns, index=index)
873+
a = result.astype(object).where(mask)
874+
b = result.astype("f8").where(mask)
875+
c = result.T.where(mask.T).T
876+
d = result.where(mask) # used to fail with "cannot reindex from a duplicate axis"
877+
tm.assert_frame_equal(a.astype("f8"), b.astype("f8"))
878+
tm.assert_frame_equal(b.astype("f8"), c.astype("f8"))
879+
tm.assert_frame_equal(c.astype("f8"), d.astype("f8"))
880+
881+
866882
def test_where_non_keyword_deprecation(frame_or_series):
867883
# GH 41485
868884
obj = frame_or_series(range(5))

0 commit comments

Comments
 (0)