Skip to content

Commit cd2506b

Browse files
committed
TST: ensure groupby get by index value pandas-dev#33439
1 parent 8aa7072 commit cd2506b

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

doc/source/whatsnew/v1.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ Other
750750
- Bug in :meth:`DataFrame.__dir__` caused a segfault when using unicode surrogates in a column name (:issue:`25509`)
751751
- Bug in :meth:`DataFrame.plot.scatter` caused an error when plotting variable marker sizes (:issue:`32904`)
752752
- :class:`IntegerArray` now implements the ``sum`` operation (:issue:`33172`)
753+
- Added test for getting values by index value during groupby aggregation (:issue:`33439`)
753754

754755
.. ---------------------------------------------------------------------------
755756

pandas/tests/groupby/aggregate/test_aggregate.py

+8
Original file line numberDiff line numberDiff line change
@@ -940,3 +940,11 @@ def test_agg_multiple_lambda(self):
940940
weight_min=pd.NamedAgg(column="weight", aggfunc=lambda x: np.min(x)),
941941
)
942942
tm.assert_frame_equal(result2, expected)
943+
944+
945+
def test_groupby_get_by_index():
946+
# GH 33439
947+
df = pd.DataFrame({"A": ["S", "W", "W"], "B": [1.0, 1.0, 2.0]})
948+
res = df.groupby("A").agg({"B": lambda x: x.get(x.index[-1])})
949+
expected = pd.DataFrame(dict(A=["S", "W"], B=[1.0, 2.0])).set_index("A")
950+
pd.testing.assert_frame_equal(res, expected)

0 commit comments

Comments
 (0)