From 908be407618b7e7911ca799d618022e2904cfba3 Mon Sep 17 00:00:00 2001 From: sam-cohan Date: Mon, 27 Apr 2020 12:28:39 -0700 Subject: [PATCH] TST: ensure groupby get by index value #33439 --- pandas/tests/groupby/aggregate/test_aggregate.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/tests/groupby/aggregate/test_aggregate.py b/pandas/tests/groupby/aggregate/test_aggregate.py index e860ea1a3d052..d4b061594c364 100644 --- a/pandas/tests/groupby/aggregate/test_aggregate.py +++ b/pandas/tests/groupby/aggregate/test_aggregate.py @@ -940,3 +940,11 @@ def test_agg_multiple_lambda(self): weight_min=pd.NamedAgg(column="weight", aggfunc=lambda x: np.min(x)), ) tm.assert_frame_equal(result2, expected) + + +def test_groupby_get_by_index(): + # GH 33439 + df = pd.DataFrame({"A": ["S", "W", "W"], "B": [1.0, 1.0, 2.0]}) + res = df.groupby("A").agg({"B": lambda x: x.get(x.index[-1])}) + expected = pd.DataFrame(dict(A=["S", "W"], B=[1.0, 2.0])).set_index("A") + pd.testing.assert_frame_equal(res, expected)