Skip to content

Commit ccc04c4

Browse files
authored
TST: Group by callable test (#55926)
* add test * lint
1 parent 0ff8968 commit ccc04c4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pandas/tests/groupby/test_grouping.py

+17
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,23 @@ def test_grouper_creation_bug3(self):
297297
expected = ser.groupby(level="one").sum()
298298
tm.assert_series_equal(result, expected)
299299

300+
@pytest.mark.parametrize("func", [False, True])
301+
def test_grouper_returning_tuples(self, func):
302+
# GH 22257 , both with dict and with callable
303+
df = DataFrame({"X": ["A", "B", "A", "B"], "Y": [1, 4, 3, 2]})
304+
mapping = dict(zip(range(4), [("C", 5), ("D", 6)] * 2))
305+
306+
if func:
307+
gb = df.groupby(by=lambda idx: mapping[idx], sort=False)
308+
else:
309+
gb = df.groupby(by=mapping, sort=False)
310+
311+
name, expected = next(iter(gb))
312+
assert name == ("C", 5)
313+
result = gb.get_group(name)
314+
315+
tm.assert_frame_equal(result, expected)
316+
300317
def test_grouper_column_and_index(self):
301318
# GH 14327
302319

0 commit comments

Comments
 (0)