Skip to content

Commit f8332ac

Browse files
authored
more test cases added
six of hopeful 8. Covered all I can think of. empty doesn't work
1 parent 438181a commit f8332ac

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

pandas/core/groupby/_test_get_groups.py

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,13 @@
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+
15
import unittest
26

37
from pandas import DataFrame
48
from pandas.testing import assert_frame_equal
59
import numpy as np
610

7-
#
8-
# # df = DataFrame({'Animal': ['Falcon', 'Falcon',
9-
# # 'Parrot', 'Parrot'],
10-
# # 'Max Speed': [380., 370., 24., 26.],
11-
# # 'bullshit': ['a', 'b', 'c', 'd']})
12-
# #
13-
# # print(df)
14-
# # grps = df.groupby(['Animal'])
15-
# # print(_GroupBy.get_group(grps, ('Falcon')))
16-
# # print("=====")
17-
# # i = 0
18-
# # for key, item in grps:
19-
# # print(i)
20-
# # i +=1
21-
# # print(key)
22-
# # print(_GroupBy.get_group(grps, key))
23-
# # print(grps)
24-
# # print(grps.mean())
25-
# # print("=====")
26-
#
27-
# d = {
28-
# "cat": pd.Categorical(
29-
# ["a", "b", "a", "b"], categories=["a", "b", "c"], ordered=True
30-
# ),
31-
# "ints": [1, 1, 2, 2],
32-
# "val": [10, 20, 30, 40],
33-
# }
34-
# df = pd.DataFrame(d)
35-
3611
class _test_get_groups(unittest.TestCase):
3712
def test_cero_discovered_invalid(self):
3813
df = DataFrame(data={
@@ -80,6 +55,27 @@ def test_tres_double_row_valid(self):
8055
grps = df.groupby(by=['B'])
8156
self.assertEqual(True, np.array_equal(grps.get_group(('b1')).values, expected.values))
8257

58+
def test_cuatro_expect_empty(self):
59+
df = DataFrame(data={
60+
'A': ['a1', 'a2', None],
61+
'B': ['b1', 'b2', 'b1'],
62+
'val': [1, 2, 3],
63+
})
64+
grps = df.groupby(by=['B'])
65+
self.assertRaises(KeyError, grps.get_group, ('b3'))
66+
67+
def test_cinco_double_row_valid(self):
68+
df = DataFrame({'Animal': ['Falcon', 'Falcon',
69+
'Parrot', 'Parrot'],
70+
'Max Speed': [380., 370., 24., 26.],
71+
'bullshit': ['a', 'b', 'c', 'd']})
72+
expected = DataFrame({'Animal': ['Falcon', 'Falcon'],
73+
'Max Speed': [380., 370.],
74+
'bullshit': ['a', 'b']})
75+
grps = df.groupby(['Animal'])
76+
assert_frame_equal(grps.get_group(('Falcon')), expected)
77+
78+
8379

8480
if __name__ == '__main__':
8581
unittest.main()

0 commit comments

Comments
 (0)