From 126b65ba35db080d0262ec6da2cd67e84e29a33f Mon Sep 17 00:00:00 2001 From: phofl Date: Tue, 15 Sep 2020 22:39:49 +0200 Subject: [PATCH 1/2] Add test to avoid regression --- pandas/tests/groupby/test_groupby.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index 313b0ea2434f9..76f6498519070 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -2126,3 +2126,14 @@ def test_groupby_column_index_name_lost(func): df_grouped = df.groupby([1]) result = getattr(df_grouped, func)().columns tm.assert_index_equal(result, expected) + + +def test_groupby_duplicate_columns(): + # GH: 31735 + df = pd.DataFrame( + {"A": ["f", "e", "g", "h"], "B": ["a", "b", "c", "d"], "C": [1, 2, 3, 4],} + ).astype(object) + df.columns = ["A", "B", "B"] + result = df.groupby([0, 0, 0, 0]).min() + expected = pd.DataFrame([["e", "a", 1]], columns=["A", "B", "B"]) + tm.assert_frame_equal(result, expected) From 1f693acdaa375e0548e1b37285f96244674cd25b Mon Sep 17 00:00:00 2001 From: phofl Date: Tue, 15 Sep 2020 22:42:25 +0200 Subject: [PATCH 2/2] Delete comma --- pandas/tests/groupby/test_groupby.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index 76f6498519070..1bb40b322cd48 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -2131,7 +2131,7 @@ def test_groupby_column_index_name_lost(func): def test_groupby_duplicate_columns(): # GH: 31735 df = pd.DataFrame( - {"A": ["f", "e", "g", "h"], "B": ["a", "b", "c", "d"], "C": [1, 2, 3, 4],} + {"A": ["f", "e", "g", "h"], "B": ["a", "b", "c", "d"], "C": [1, 2, 3, 4]} ).astype(object) df.columns = ["A", "B", "B"] result = df.groupby([0, 0, 0, 0]).min()