Skip to content

Commit 5e96797

Browse files
author
Jon M. Mease
committed
Add tests for grouping on two columns
1 parent cee5ce6 commit 5e96797

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

pandas/tests/test_groupby.py

+24
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,34 @@ def test_grouper_creation_bug(self):
444444

445445
# GH14334
446446
# pd.Grouper(key=...) may be passed in a list
447+
df = DataFrame({'A': [0, 0, 0, 1, 1, 1],
448+
'B': [1, 1, 2, 2, 3, 3],
449+
'C': [1, 2, 3, 4, 5, 6]})
450+
# Group by single column
451+
expected = df.groupby('A').sum()
447452
g = df.groupby([pd.Grouper(key='A')])
448453
result = g.sum()
449454
assert_frame_equal(result, expected)
450455

456+
# Group by two columns
457+
# using a combination of strings and Grouper objects
458+
expected = df.groupby(['A', 'B']).sum()
459+
460+
# Group with two Grouper objects
461+
g = df.groupby([pd.Grouper(key='A'), pd.Grouper(key='B')])
462+
result = g.sum()
463+
assert_frame_equal(result, expected)
464+
465+
# Group with a string and a Grouper object
466+
g = df.groupby(['A', pd.Grouper(key='B')])
467+
result = g.sum()
468+
assert_frame_equal(result, expected)
469+
470+
# Group with a Grouper object and a string
471+
g = df.groupby([pd.Grouper(key='A'), 'B'])
472+
result = g.sum()
473+
assert_frame_equal(result, expected)
474+
451475
# GH8866
452476
s = Series(np.arange(8, dtype='int64'),
453477
index=pd.MultiIndex.from_product(

0 commit comments

Comments
 (0)