Skip to content

TST: a weird bug with numpy + DataFrame with duplicate columns #38354

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 8 commits into from
Dec 8, 2020
Merged
33 changes: 33 additions & 0 deletions pandas/tests/frame/test_nonunique_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,3 +486,36 @@ def test_set_value_by_index(self):

df.iloc[:, 0] = 3
tm.assert_series_equal(df.iloc[:, 1], expected)

@pytest.mark.parametrize(
"data1,data2,expected_data",
(
(
[[1, 2], [3, 4]],
[[0.5, 6], [7, 8]],
[[np.nan, 3.0], [np.nan, 4.0], [np.nan, 7.0], [6.0, 8.0]],
),
(
[[1, 2], [3, 4]],
[[5, 6], [7, 8]],
[[np.nan, 3.0], [np.nan, 4.0], [5, 7], [6, 8]],
),
),
)
def test_masking_duplicate_columns_mixed_dtypes(
self,
data1,
data2,
expected_data,
):
# GH31954

df1 = DataFrame(np.array(data1))
df2 = DataFrame(np.array(data2))
df = pd.concat([df1, df2], axis=1)

result = df[df > 2]
expected = DataFrame(
{i: np.array(col) for i, col in enumerate(expected_data)}
).rename(columns={2: 0, 3: 1})
tm.assert_frame_equal(result, expected)