|
| 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 | + |
1 | 5 | import unittest
|
2 | 6 |
|
3 | 7 | from pandas import DataFrame
|
4 | 8 | from pandas.testing import assert_frame_equal
|
5 | 9 | import numpy as np
|
6 | 10 |
|
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 |
| - |
36 | 11 | class _test_get_groups(unittest.TestCase):
|
37 | 12 | def test_cero_discovered_invalid(self):
|
38 | 13 | df = DataFrame(data={
|
@@ -80,6 +55,27 @@ def test_tres_double_row_valid(self):
|
80 | 55 | grps = df.groupby(by=['B'])
|
81 | 56 | self.assertEqual(True, np.array_equal(grps.get_group(('b1')).values, expected.values))
|
82 | 57 |
|
| 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 | + |
83 | 79 |
|
84 | 80 | if __name__ == '__main__':
|
85 | 81 | unittest.main()
|
0 commit comments