8
8
9
9
10
10
class TestGrouperGrouping :
11
- def setup_method (self , method ):
11
+ def setup_method (self ):
12
12
self .series = Series (np .arange (10 ))
13
13
self .frame = DataFrame ({"A" : [1 ] * 20 + [2 ] * 12 + [3 ] * 8 , "B" : np .arange (40 )})
14
14
@@ -55,19 +55,25 @@ def test_getitem_multiple(self):
55
55
result = r .B .count ()
56
56
tm .assert_series_equal (result , expected )
57
57
58
- def test_rolling (self ):
58
+ @pytest .mark .parametrize (
59
+ "f" , ["sum" , "mean" , "min" , "max" , "count" , "kurt" , "skew" ]
60
+ )
61
+ def test_rolling (self , f ):
59
62
g = self .frame .groupby ("A" )
60
63
r = g .rolling (window = 4 )
61
64
62
- for f in ["sum" , "mean" , "min" , "max" , "count" , "kurt" , "skew" ]:
63
- result = getattr (r , f )()
64
- expected = g .apply (lambda x : getattr (x .rolling (4 ), f )())
65
- tm .assert_frame_equal (result , expected )
65
+ result = getattr (r , f )()
66
+ expected = g .apply (lambda x : getattr (x .rolling (4 ), f )())
67
+ tm .assert_frame_equal (result , expected )
66
68
67
- for f in ["std" , "var" ]:
68
- result = getattr (r , f )(ddof = 1 )
69
- expected = g .apply (lambda x : getattr (x .rolling (4 ), f )(ddof = 1 ))
70
- tm .assert_frame_equal (result , expected )
69
+ @pytest .mark .parametrize ("f" , ["std" , "var" ])
70
+ def test_rolling_ddof (self , f ):
71
+ g = self .frame .groupby ("A" )
72
+ r = g .rolling (window = 4 )
73
+
74
+ result = getattr (r , f )(ddof = 1 )
75
+ expected = g .apply (lambda x : getattr (x .rolling (4 ), f )(ddof = 1 ))
76
+ tm .assert_frame_equal (result , expected )
71
77
72
78
@pytest .mark .parametrize (
73
79
"interpolation" , ["linear" , "lower" , "higher" , "midpoint" , "nearest" ]
@@ -81,26 +87,26 @@ def test_rolling_quantile(self, interpolation):
81
87
)
82
88
tm .assert_frame_equal (result , expected )
83
89
84
- def test_rolling_corr_cov (self ):
90
+ @pytest .mark .parametrize ("f" , ["corr" , "cov" ])
91
+ def test_rolling_corr_cov (self , f ):
85
92
g = self .frame .groupby ("A" )
86
93
r = g .rolling (window = 4 )
87
94
88
- for f in ["corr" , "cov" ]:
89
- result = getattr (r , f )(self .frame )
95
+ result = getattr (r , f )(self .frame )
90
96
91
- def func (x ):
92
- return getattr (x .rolling (4 ), f )(self .frame )
97
+ def func (x ):
98
+ return getattr (x .rolling (4 ), f )(self .frame )
93
99
94
- expected = g .apply (func )
95
- tm .assert_frame_equal (result , expected )
100
+ expected = g .apply (func )
101
+ tm .assert_frame_equal (result , expected )
96
102
97
- result = getattr (r .B , f )(pairwise = True )
103
+ result = getattr (r .B , f )(pairwise = True )
98
104
99
- def func (x ):
100
- return getattr (x .B .rolling (4 ), f )(pairwise = True )
105
+ def func (x ):
106
+ return getattr (x .B .rolling (4 ), f )(pairwise = True )
101
107
102
- expected = g .apply (func )
103
- tm .assert_series_equal (result , expected )
108
+ expected = g .apply (func )
109
+ tm .assert_series_equal (result , expected )
104
110
105
111
def test_rolling_apply (self , raw ):
106
112
g = self .frame .groupby ("A" )
@@ -134,20 +140,25 @@ def test_rolling_apply_mutability(self):
134
140
result = g .rolling (window = 2 ).sum ()
135
141
tm .assert_frame_equal (result , expected )
136
142
137
- def test_expanding (self ):
143
+ @pytest .mark .parametrize (
144
+ "f" , ["sum" , "mean" , "min" , "max" , "count" , "kurt" , "skew" ]
145
+ )
146
+ def test_expanding (self , f ):
138
147
g = self .frame .groupby ("A" )
139
148
r = g .expanding ()
140
149
141
- for f in ["sum" , "mean" , "min" , "max" , "count" , "kurt" , "skew" ]:
150
+ result = getattr (r , f )()
151
+ expected = g .apply (lambda x : getattr (x .expanding (), f )())
152
+ tm .assert_frame_equal (result , expected )
142
153
143
- result = getattr (r , f )()
144
- expected = g .apply (lambda x : getattr (x .expanding (), f )())
145
- tm .assert_frame_equal (result , expected )
154
+ @pytest .mark .parametrize ("f" , ["std" , "var" ])
155
+ def test_expanding_ddof (self , f ):
156
+ g = self .frame .groupby ("A" )
157
+ r = g .expanding ()
146
158
147
- for f in ["std" , "var" ]:
148
- result = getattr (r , f )(ddof = 0 )
149
- expected = g .apply (lambda x : getattr (x .expanding (), f )(ddof = 0 ))
150
- tm .assert_frame_equal (result , expected )
159
+ result = getattr (r , f )(ddof = 0 )
160
+ expected = g .apply (lambda x : getattr (x .expanding (), f )(ddof = 0 ))
161
+ tm .assert_frame_equal (result , expected )
151
162
152
163
@pytest .mark .parametrize (
153
164
"interpolation" , ["linear" , "lower" , "higher" , "midpoint" , "nearest" ]
@@ -161,26 +172,26 @@ def test_expanding_quantile(self, interpolation):
161
172
)
162
173
tm .assert_frame_equal (result , expected )
163
174
164
- def test_expanding_corr_cov (self ):
175
+ @pytest .mark .parametrize ("f" , ["corr" , "cov" ])
176
+ def test_expanding_corr_cov (self , f ):
165
177
g = self .frame .groupby ("A" )
166
178
r = g .expanding ()
167
179
168
- for f in ["corr" , "cov" ]:
169
- result = getattr (r , f )(self .frame )
180
+ result = getattr (r , f )(self .frame )
170
181
171
- def func (x ):
172
- return getattr (x .expanding (), f )(self .frame )
182
+ def func (x ):
183
+ return getattr (x .expanding (), f )(self .frame )
173
184
174
- expected = g .apply (func )
175
- tm .assert_frame_equal (result , expected )
185
+ expected = g .apply (func )
186
+ tm .assert_frame_equal (result , expected )
176
187
177
- result = getattr (r .B , f )(pairwise = True )
188
+ result = getattr (r .B , f )(pairwise = True )
178
189
179
- def func (x ):
180
- return getattr (x .B .expanding (), f )(pairwise = True )
190
+ def func (x ):
191
+ return getattr (x .B .expanding (), f )(pairwise = True )
181
192
182
- expected = g .apply (func )
183
- tm .assert_series_equal (result , expected )
193
+ expected = g .apply (func )
194
+ tm .assert_series_equal (result , expected )
184
195
185
196
def test_expanding_apply (self , raw ):
186
197
g = self .frame .groupby ("A" )
0 commit comments