Skip to content

Commit

Permalink
BUG: Add test to ensure, that bug will not occur again. #33058 (#33072)
Browse files Browse the repository at this point in the history
  • Loading branch information
phofl authored Apr 10, 2020
1 parent f334fcc commit 31ea45f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pandas/tests/groupby/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,3 +880,24 @@ def test_apply_function_index_return(function):
index=pd.Index([1, 2, 3], name="id"),
)
tm.assert_series_equal(result, expected)


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]}
)

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)

0 comments on commit 31ea45f

Please sign in to comment.