From a57d377e5a868bd28bdd8926bf29df879044a051 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Thu, 3 Dec 2020 00:46:11 +0700 Subject: [PATCH] TST: setitem in presence of duplicate cols --- pandas/tests/frame/indexing/test_indexing.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pandas/tests/frame/indexing/test_indexing.py b/pandas/tests/frame/indexing/test_indexing.py index 6d4129a1a2a55..49eb570c4ffe0 100644 --- a/pandas/tests/frame/indexing/test_indexing.py +++ b/pandas/tests/frame/indexing/test_indexing.py @@ -241,6 +241,24 @@ def inc(x): expected = DataFrame([[-1, inc], [inc, -1]]) tm.assert_frame_equal(df, expected) + @pytest.mark.parametrize( + "cols, values, expected", + [ + (["C", "D", "D", "a"], [1, 2, 3, 4], 4), # with duplicates + (["D", "C", "D", "a"], [1, 2, 3, 4], 4), # mixed order + (["C", "B", "B", "a"], [1, 2, 3, 4], 4), # other duplicate cols + (["C", "B", "a"], [1, 2, 3], 3), # no duplicates + (["B", "C", "a"], [3, 2, 1], 1), # alphabetical order + (["C", "a", "B"], [3, 2, 1], 2), # in the middle + ], + ) + def test_setitem_same_column(self, cols, values, expected): + # GH 23239 + df = DataFrame([values], columns=cols) + df["a"] = df["a"] + result = df["a"].values[0] + assert result == expected + def test_getitem_boolean( self, float_string_frame, mixed_float_frame, mixed_int_frame, datetime_frame ):