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
4
4
5
5
import unittest
6
6
9
9
import numpy as np
10
10
11
11
class _test_get_groups (unittest .TestCase ):
12
- def test_cero_discovered_invalid (self ):
12
+ def test_discovered_invalid (self ):
13
13
df = DataFrame (data = {
14
14
'A' : ['a1' , 'a2' , None ],
15
15
'B' : ['b1' , 'b2' , 'b1' ],
@@ -18,7 +18,7 @@ def test_cero_discovered_invalid(self):
18
18
grps = df .groupby (by = ['A' , 'B' ])
19
19
self .assertRaises (KeyError , grps .get_group , ('a1' , 'b2' ))
20
20
21
- def test_uno_single_row_valid (self ):
21
+ def test_single_row_valid (self ):
22
22
df = DataFrame (data = {
23
23
'A' : ['a1' , 'a2' , None ],
24
24
'B' : ['b1' , 'b2' , 'b1' ],
@@ -32,7 +32,7 @@ def test_uno_single_row_valid(self):
32
32
grps = df .groupby (by = ['A' , 'B' ])
33
33
assert_frame_equal (grps .get_group (('a1' , 'b1' )), expected )
34
34
35
- def test_dos_alternate_invalid (self ):
35
+ def test_alternate_invalid (self ):
36
36
df = DataFrame (data = {
37
37
'A' : ['a1' , 'a2' , None ],
38
38
'B' : ['b1' , 'b2' , 'b1' ],
@@ -41,7 +41,7 @@ def test_dos_alternate_invalid(self):
41
41
grps = df .groupby (by = ['A' , 'B' ])
42
42
self .assertRaises (KeyError , grps .get_group , ('a2' , 'b1' ))
43
43
44
- def test_tres_double_row_valid (self ):
44
+ def test_double_row_valid (self ):
45
45
df = DataFrame (data = {
46
46
'A' : ['a1' , 'a2' , None ],
47
47
'B' : ['b1' , 'b2' , 'b1' ],
@@ -55,7 +55,7 @@ def test_tres_double_row_valid(self):
55
55
grps = df .groupby (by = ['B' ])
56
56
self .assertEqual (True , np .array_equal (grps .get_group (('b1' )).values , expected .values ))
57
57
58
- def test_cuatro_expect_empty (self ):
58
+ def test_expect_empty (self ):
59
59
df = DataFrame (data = {
60
60
'A' : ['a1' , 'a2' , None ],
61
61
'B' : ['b1' , 'b2' , 'b1' ],
@@ -64,7 +64,7 @@ def test_cuatro_expect_empty(self):
64
64
grps = df .groupby (by = ['B' ])
65
65
self .assertRaises (KeyError , grps .get_group , ('b3' ))
66
66
67
- def test_cinco_double_row_valid (self ):
67
+ def test_double_row_valid (self ):
68
68
df = DataFrame ({'Animal' : ['Falcon' , 'Falcon' ,
69
69
'Parrot' , 'Parrot' ],
70
70
'Max Speed' : [380. , 370. , 24. , 26. ],
@@ -75,7 +75,35 @@ def test_cinco_double_row_valid(self):
75
75
grps = df .groupby (['Animal' ])
76
76
assert_frame_equal (grps .get_group (('Falcon' )), expected )
77
77
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 )
78
92
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 )
79
107
80
108
if __name__ == '__main__' :
81
109
unittest .main ()
0 commit comments