From ca15eb68317c0b3756934c02ea4ac6a8cebc7124 Mon Sep 17 00:00:00 2001 From: phofl Date: Fri, 27 Mar 2020 17:58:57 +0100 Subject: [PATCH 1/3] BUG: Add test to ensure, that bug will not occur again. #33058 --- pandas/tests/groupby/test_apply.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index 18ad5d90b3f60..b915ddf7bbad5 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -866,3 +866,24 @@ def fct(group): [[1.0, 2.0], [3.0], [np.nan]], index=pd.Index(["a", "b", "none"], name="A") ) tm.assert_series_equal(result, expected) + + +def test_apply_function_adds_a_row(): + # GH: 33058 + df = pd.DataFrame( + {"col1": ["A", "A", "A", "B", "B", "B"], "col2": [1, 2, 3, 4, 5, 6]} + ) + + def fn(x): + x.col2[x.index[-1]] = 0 + return x.col2 + + result = df.groupby(["col1"], as_index=False).apply(fn) + expected = pd.Series( + [1, 2, 0, 4, 5, 0], + index=pd.MultiIndex.from_tuples( + [(0, 0), (0, 1), (0, 2), (1, 3), (1, 4), (1, 5)] + ), + name="col2", + ) + tm.assert_series_equal(result, expected) From 1c86084a376325de9c6751702f28e96e7c43a2a7 Mon Sep 17 00:00:00 2001 From: patrick Date: Fri, 27 Mar 2020 18:41:30 +0100 Subject: [PATCH 2/3] BUG: Change test name upon request --- pandas/tests/groupby/test_apply.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index b915ddf7bbad5..7288bf6d00512 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -868,7 +868,7 @@ def fct(group): tm.assert_series_equal(result, expected) -def test_apply_function_adds_a_row(): +def test_apply_function_with_indexing(): # GH: 33058 df = pd.DataFrame( {"col1": ["A", "A", "A", "B", "B", "B"], "col2": [1, 2, 3, 4, 5, 6]} From 46b5635b8cd103fa723902ff38d9f8558a2382c0 Mon Sep 17 00:00:00 2001 From: phofl Date: Thu, 2 Apr 2020 21:12:03 +0200 Subject: [PATCH 3/3] Add new line. Occurred during merge --- pandas/tests/groupby/test_apply.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index 4a0c883fc7b43..9fcbabb07857e 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -900,4 +900,4 @@ def fn(x): ), name="col2", ) - tm.assert_series_equal(result, expected) \ No newline at end of file + tm.assert_series_equal(result, expected)