Skip to content

Commit eddf0fb

Browse files
committed
Added more test cases
1 parent f8332ac commit eddf0fb

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

pandas/core/groupby/_test_get_groups.py

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# DO NOT MERGE _test_get_groups.py WITH ACTUAL PANDAS
2-
# DO NOT MERGE _test_get_groups.py WITH ACTUAL PANDAS
3-
# DO NOT MERGE _test_get_groups.py WITH ACTUAL PANDAS
1+
# DO NOT MERGE _test_get_groups.py WITH ACTUAL PANDAS
2+
# DO NOT MERGE _test_get_groups.py WITH ACTUAL PANDAS
3+
# DO NOT MERGE _test_get_groups.py WITH ACTUAL PANDAS
44

55
import unittest
66

@@ -9,7 +9,7 @@
99
import numpy as np
1010

1111
class _test_get_groups(unittest.TestCase):
12-
def test_cero_discovered_invalid(self):
12+
def test_discovered_invalid(self):
1313
df = DataFrame(data={
1414
'A': ['a1', 'a2', None],
1515
'B': ['b1', 'b2', 'b1'],
@@ -18,7 +18,7 @@ def test_cero_discovered_invalid(self):
1818
grps = df.groupby(by=['A', 'B'])
1919
self.assertRaises(KeyError, grps.get_group, ('a1', 'b2'))
2020

21-
def test_uno_single_row_valid(self):
21+
def test_single_row_valid(self):
2222
df = DataFrame(data={
2323
'A': ['a1', 'a2', None],
2424
'B': ['b1', 'b2', 'b1'],
@@ -32,7 +32,7 @@ def test_uno_single_row_valid(self):
3232
grps = df.groupby(by=['A', 'B'])
3333
assert_frame_equal(grps.get_group(('a1', 'b1')), expected)
3434

35-
def test_dos_alternate_invalid(self):
35+
def test_alternate_invalid(self):
3636
df = DataFrame(data={
3737
'A': ['a1', 'a2', None],
3838
'B': ['b1', 'b2', 'b1'],
@@ -41,7 +41,7 @@ def test_dos_alternate_invalid(self):
4141
grps = df.groupby(by=['A', 'B'])
4242
self.assertRaises(KeyError, grps.get_group, ('a2', 'b1'))
4343

44-
def test_tres_double_row_valid(self):
44+
def test_double_row_valid(self):
4545
df = DataFrame(data={
4646
'A': ['a1', 'a2', None],
4747
'B': ['b1', 'b2', 'b1'],
@@ -55,7 +55,7 @@ def test_tres_double_row_valid(self):
5555
grps = df.groupby(by=['B'])
5656
self.assertEqual(True, np.array_equal(grps.get_group(('b1')).values, expected.values))
5757

58-
def test_cuatro_expect_empty(self):
58+
def test_expect_empty(self):
5959
df = DataFrame(data={
6060
'A': ['a1', 'a2', None],
6161
'B': ['b1', 'b2', 'b1'],
@@ -64,7 +64,7 @@ def test_cuatro_expect_empty(self):
6464
grps = df.groupby(by=['B'])
6565
self.assertRaises(KeyError, grps.get_group, ('b3'))
6666

67-
def test_cinco_double_row_valid(self):
67+
def test_double_row_valid(self):
6868
df = DataFrame({'Animal': ['Falcon', 'Falcon',
6969
'Parrot', 'Parrot'],
7070
'Max Speed': [380., 370., 24., 26.],
@@ -75,7 +75,35 @@ def test_cinco_double_row_valid(self):
7575
grps = df.groupby(['Animal'])
7676
assert_frame_equal(grps.get_group(('Falcon')), expected)
7777

78+
def test_multi_group_multi_result(self):
79+
df = DataFrame([('bird', 'Falconiformes', 389.0),
80+
('bird', 'Psittaciformes', 24.0),
81+
('mammal', 'Carnivora', 80.2),
82+
('mammal', 'Primates', None),
83+
('mammal', 'Carnivora', 58)],
84+
index=['falcon', 'parrot', 'lion', 'monkey', 'leopard'],
85+
columns=('class', 'order', 'max_speed'))
86+
expected = DataFrame([('mammal', 'Carnivora', 80.2),
87+
('mammal', 'Carnivora', 58)],
88+
index=['lion', 'leopard'],
89+
columns=('class', 'order', 'max_speed'))
90+
grps = df.groupby(['class', 'order']);
91+
assert_frame_equal(grps.get_group(('mammal','Carnivora')), expected)
7892

93+
def test_single_group_no_tuple(self):
94+
df = DataFrame([('bird', 'Falconiformes', 389.0),
95+
('bird', 'Psittaciformes', 24.0),
96+
('mammal', 'Carnivora', 80.2),
97+
('mammal', 'Primates', None),
98+
('mammal', 'Carnivora', 58)],
99+
index=['falcon', 'parrot', 'lion', 'monkey', 'leopard'],
100+
columns=('class', 'order', 'max_speed'))
101+
expected = DataFrame([('bird', 'Falconiformes', 389.0),
102+
('bird', 'Psittaciformes', 24.0)],
103+
index=['falcon', 'parrot'],
104+
columns=('class', 'order', 'max_speed'))
105+
grps = df.groupby(['class']);
106+
assert_frame_equal(grps.get_group('bird'), expected)
79107

80108
if __name__ == '__main__':
81109
unittest.main()

0 commit comments

Comments
 (0)