@@ -57,11 +57,12 @@ def test_groupby_with_timegrouper(self):
57
57
result3 = df .groupby (pd .Grouper (freq = '5D' )).sum ()
58
58
assert_frame_equal (result3 , expected )
59
59
60
- def test_groupby_with_timegrouper_methods (self ):
60
+ @pytest .mark .parametrize ("should_sort" , [True , False ])
61
+ def test_groupby_with_timegrouper_methods (self , should_sort ):
61
62
# GH 3881
62
63
# make sure API of timegrouper conforms
63
64
64
- df_original = pd .DataFrame ({
65
+ df = pd .DataFrame ({
65
66
'Branch' : 'A A A A A B' .split (),
66
67
'Buyer' : 'Carl Mark Carl Joe Joe Carl' .split (),
67
68
'Quantity' : [1 , 3 , 5 , 8 , 9 , 3 ],
@@ -75,16 +76,18 @@ def test_groupby_with_timegrouper_methods(self):
75
76
]
76
77
})
77
78
78
- df_sorted = df_original .sort_values (by = 'Quantity' , ascending = False )
79
+ if should_sort :
80
+ df = df .sort_values (by = 'Quantity' , ascending = False )
79
81
80
- for df in [df_original , df_sorted ]:
81
- df = df .set_index ('Date' , drop = False )
82
- g = df .groupby (pd .Grouper (freq = '6M' ))
83
- assert g .group_keys
84
- assert isinstance (g .grouper , pd .core .groupby .BinGrouper )
85
- groups = g .groups
86
- assert isinstance (groups , dict )
87
- assert len (groups ) == 3
82
+ df = df .set_index ('Date' , drop = False )
83
+ g = df .groupby (pd .Grouper (freq = '6M' ))
84
+ assert g .group_keys
85
+
86
+ import pandas .core .groupby .groupby
87
+ assert isinstance (g .grouper , pandas .core .groupby .groupby .BinGrouper )
88
+ groups = g .groups
89
+ assert isinstance (groups , dict )
90
+ assert len (groups ) == 3
88
91
89
92
def test_timegrouper_with_reg_groups (self ):
90
93
0 commit comments