Skip to content

Commit 9b8f50b

Browse files
authored
TST: a weird bug with numpy + DataFrame with duplicate columns (#38354)
1 parent 8878ec6 commit 9b8f50b

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

pandas/tests/frame/test_nonunique_indexes.py

+33
Original file line numberDiff line numberDiff line change
@@ -486,3 +486,36 @@ def test_set_value_by_index(self):
486486

487487
df.iloc[:, 0] = 3
488488
tm.assert_series_equal(df.iloc[:, 1], expected)
489+
490+
@pytest.mark.parametrize(
491+
"data1,data2,expected_data",
492+
(
493+
(
494+
[[1, 2], [3, 4]],
495+
[[0.5, 6], [7, 8]],
496+
[[np.nan, 3.0], [np.nan, 4.0], [np.nan, 7.0], [6.0, 8.0]],
497+
),
498+
(
499+
[[1, 2], [3, 4]],
500+
[[5, 6], [7, 8]],
501+
[[np.nan, 3.0], [np.nan, 4.0], [5, 7], [6, 8]],
502+
),
503+
),
504+
)
505+
def test_masking_duplicate_columns_mixed_dtypes(
506+
self,
507+
data1,
508+
data2,
509+
expected_data,
510+
):
511+
# GH31954
512+
513+
df1 = DataFrame(np.array(data1))
514+
df2 = DataFrame(np.array(data2))
515+
df = pd.concat([df1, df2], axis=1)
516+
517+
result = df[df > 2]
518+
expected = DataFrame(
519+
{i: np.array(col) for i, col in enumerate(expected_data)}
520+
).rename(columns={2: 0, 3: 1})
521+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)