Skip to content

Commit 438181a

Browse files
authored
more tests with proper ordering
1 parent 9f51b8c commit 438181a

File tree

1 file changed

+59
-9
lines changed

1 file changed

+59
-9
lines changed
Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,49 @@
1-
# DO NOT MERGE _test_get_groups.py WITH THE MAIN PANDAS REPO!!!
2-
# DO NOT MERGE _test_get_groups.py WITH THE MAIN PANDAS REPO!!!
3-
# DO NOT MERGE _test_get_groups.py WITH THE MAIN PANDAS REPO!!!
4-
5-
# run with python3 _test_get_groups.py
6-
71
import unittest
82

93
from pandas import DataFrame
104
from pandas.testing import assert_frame_equal
5+
import numpy as np
116

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)
1235

1336
class _test_get_groups(unittest.TestCase):
14-
def test_single_row_valid(self):
37+
def test_cero_discovered_invalid(self):
38+
df = DataFrame(data={
39+
'A': ['a1', 'a2', None],
40+
'B': ['b1', 'b2', 'b1'],
41+
'val': [1, 2, 3],
42+
})
43+
grps = df.groupby(by=['A', 'B'])
44+
self.assertRaises(KeyError, grps.get_group, ('a1', 'b2'))
45+
46+
def test_uno_single_row_valid(self):
1547
df = DataFrame(data={
1648
'A': ['a1', 'a2', None],
1749
'B': ['b1', 'b2', 'b1'],
@@ -25,11 +57,29 @@ def test_single_row_valid(self):
2557
grps = df.groupby(by=['A', 'B'])
2658
assert_frame_equal(grps.get_group(('a1', 'b1')), expected)
2759

28-
def test_discovered_invalid(self):
60+
def test_dos_alternate_invalid(self):
2961
df = DataFrame(data={
3062
'A': ['a1', 'a2', None],
3163
'B': ['b1', 'b2', 'b1'],
3264
'val': [1, 2, 3],
3365
})
3466
grps = df.groupby(by=['A', 'B'])
35-
self.assertRaises(KeyError, grps.get_group, ('a1', 'b2'))
67+
self.assertRaises(KeyError, grps.get_group, ('a2', 'b1'))
68+
69+
def test_tres_double_row_valid(self):
70+
df = DataFrame(data={
71+
'A': ['a1', 'a2', None],
72+
'B': ['b1', 'b2', 'b1'],
73+
'val': [1, 2, 3],
74+
})
75+
expected = DataFrame(data={
76+
'A': ['a1', None],
77+
'B': ['b1', 'b1'],
78+
'val': [1, 3],
79+
})
80+
grps = df.groupby(by=['B'])
81+
self.assertEqual(True, np.array_equal(grps.get_group(('b1')).values, expected.values))
82+
83+
84+
if __name__ == '__main__':
85+
unittest.main()

0 commit comments

Comments
 (0)