Skip to content

Commit 70abd64

Browse files
authored
TST: setitem in presence of duplicate cols (#38241)
1 parent ff89f8f commit 70abd64

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pandas/tests/frame/indexing/test_indexing.py

+18
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,24 @@ def inc(x):
241241
expected = DataFrame([[-1, inc], [inc, -1]])
242242
tm.assert_frame_equal(df, expected)
243243

244+
@pytest.mark.parametrize(
245+
"cols, values, expected",
246+
[
247+
(["C", "D", "D", "a"], [1, 2, 3, 4], 4), # with duplicates
248+
(["D", "C", "D", "a"], [1, 2, 3, 4], 4), # mixed order
249+
(["C", "B", "B", "a"], [1, 2, 3, 4], 4), # other duplicate cols
250+
(["C", "B", "a"], [1, 2, 3], 3), # no duplicates
251+
(["B", "C", "a"], [3, 2, 1], 1), # alphabetical order
252+
(["C", "a", "B"], [3, 2, 1], 2), # in the middle
253+
],
254+
)
255+
def test_setitem_same_column(self, cols, values, expected):
256+
# GH 23239
257+
df = DataFrame([values], columns=cols)
258+
df["a"] = df["a"]
259+
result = df["a"].values[0]
260+
assert result == expected
261+
244262
def test_getitem_boolean(
245263
self, float_string_frame, mixed_float_frame, mixed_int_frame, datetime_frame
246264
):

0 commit comments

Comments
 (0)