Skip to content

Commit 53015df

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

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/test_groupby.py

+8
Original file line numberDiff line numberDiff line change
@@ -2012,3 +2012,11 @@ def test_groups_repr_truncates(max_seq_items, expected):
20122012

20132013
result = df.groupby(np.array(df.a)).groups.__repr__()
20142014
assert result == expected
2015+
2016+
2017+
def test_groupby_get_by_index():
2018+
# GH 33439
2019+
df = pd.DataFrame({"A": ["S", "W", "W"], "B": [1.0, 1.0, 2.0]})
2020+
res = df.groupby("A").agg({"B": lambda x: x.get(x.index[-1])})
2021+
expected = pd.DataFrame(dict(A=["S", "W"], B=[1.0, 2.0])).set_index("A")
2022+
pd.testing.assert_frame_equal(res, expected)

0 commit comments

Comments
 (0)