From 826df19f41481fa2fdbb91fd4af5f941a6a3360a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mitlas=C3=B3czki=20Bence?= Date: Thu, 24 Feb 2022 12:51:14 +0000 Subject: [PATCH 1/2] closes #25399 --- pandas/tests/frame/indexing/test_where.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pandas/tests/frame/indexing/test_where.py b/pandas/tests/frame/indexing/test_where.py index ca050a7d7db4a..1cf1ddd9a1ef8 100644 --- a/pandas/tests/frame/indexing/test_where.py +++ b/pandas/tests/frame/indexing/test_where.py @@ -12,6 +12,7 @@ from pandas import ( DataFrame, DatetimeIndex, + Index, Series, StringDtype, Timestamp, @@ -863,6 +864,28 @@ 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)) From 7c8179af9b69b23c88c8221926af7096799362a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mitlas=C3=B3czki=20Bence?= Date: Thu, 24 Feb 2022 13:24:28 +0000 Subject: [PATCH 2/2] fixed pre-commit-related issues --- pandas/tests/frame/indexing/test_where.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/pandas/tests/frame/indexing/test_where.py b/pandas/tests/frame/indexing/test_where.py index 1cf1ddd9a1ef8..51013adc0b907 100644 --- a/pandas/tests/frame/indexing/test_where.py +++ b/pandas/tests/frame/indexing/test_where.py @@ -867,23 +867,16 @@ def test_where_none_nan_coerce(): 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']) - ) + result = DataFrame(data=[[0, np.nan]], columns=Index(["A", "A"])) index, columns = result.axes - mask = DataFrame( - data=[[True, True]], - columns=columns, - index=index - ) + mask = DataFrame(data=[[True, True]], columns=columns, index=index) a = result.astype(object).where(mask) - b = result.astype('f8').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')) + 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):