@@ -29,17 +29,16 @@ def test_cov(self, float_frame, float_string_frame):
29
29
frame = float_frame .copy ()
30
30
frame ["A" ][:5 ] = np .nan
31
31
frame ["B" ][5 :10 ] = np .nan
32
- result = float_frame .cov (min_periods = len (float_frame ) - 8 )
33
- expected = float_frame .cov ()
32
+ result = frame .cov (min_periods = len (frame ) - 8 )
33
+ expected = frame .cov ()
34
34
expected .loc ["A" , "B" ] = np .nan
35
35
expected .loc ["B" , "A" ] = np .nan
36
+ tm .assert_frame_equal (result , expected )
36
37
37
38
# regular
38
- float_frame ["A" ][:5 ] = np .nan
39
- float_frame ["B" ][:10 ] = np .nan
40
- cov = float_frame .cov ()
41
-
42
- tm .assert_almost_equal (cov ["A" ]["C" ], float_frame ["A" ].cov (float_frame ["C" ]))
39
+ result = frame .cov ()
40
+ expected = frame ["A" ].cov (frame ["C" ])
41
+ tm .assert_almost_equal (result ["A" ]["C" ], expected )
43
42
44
43
# exclude non-numeric types
45
44
result = float_string_frame .cov ()
@@ -101,10 +100,7 @@ def test_corr_scipy_method(self, float_frame, method):
101
100
# ---------------------------------------------------------------------
102
101
103
102
@td .skip_if_no_scipy
104
- def test_corr_non_numeric (self , float_frame , float_string_frame ):
105
- float_frame ["A" ][:5 ] = np .nan
106
- float_frame ["B" ][5 :10 ] = np .nan
107
-
103
+ def test_corr_non_numeric (self , float_string_frame ):
108
104
# exclude non-numeric types
109
105
result = float_string_frame .corr ()
110
106
expected = float_string_frame .loc [:, ["A" , "B" , "C" , "D" ]].corr ()
@@ -143,27 +139,27 @@ def test_corr_constant(self, meth):
143
139
assert isna (rs .values ).all ()
144
140
145
141
@td .skip_if_no_scipy
146
- def test_corr_int_and_boolean (self ):
142
+ @pytest .mark .parametrize ("meth" , ["pearson" , "kendall" , "spearman" ])
143
+ def test_corr_int_and_boolean (self , meth ):
147
144
# when dtypes of pandas series are different
148
145
# then ndarray will have dtype=object,
149
146
# so it need to be properly handled
150
147
df = DataFrame ({"a" : [True , False ], "b" : [1 , 0 ]})
151
148
152
149
expected = DataFrame (np .ones ((2 , 2 )), index = ["a" , "b" ], columns = ["a" , "b" ])
153
- for meth in ["pearson" , "kendall" , "spearman" ]:
154
150
155
- with warnings .catch_warnings (record = True ):
156
- warnings .simplefilter ("ignore" , RuntimeWarning )
157
- result = df .corr (meth )
158
- tm .assert_frame_equal (result , expected )
151
+ with warnings .catch_warnings (record = True ):
152
+ warnings .simplefilter ("ignore" , RuntimeWarning )
153
+ result = df .corr (meth )
154
+ tm .assert_frame_equal (result , expected )
159
155
160
- def test_corr_cov_independent_index_column (self ):
156
+ @pytest .mark .parametrize ("method" , ["cov" , "corr" ])
157
+ def test_corr_cov_independent_index_column (self , method ):
161
158
# GH#14617
162
159
df = DataFrame (np .random .randn (4 * 10 ).reshape (10 , 4 ), columns = list ("abcd" ))
163
- for method in ["cov" , "corr" ]:
164
- result = getattr (df , method )()
165
- assert result .index is not result .columns
166
- assert result .index .equals (result .columns )
160
+ result = getattr (df , method )()
161
+ assert result .index is not result .columns
162
+ assert result .index .equals (result .columns )
167
163
168
164
def test_corr_invalid_method (self ):
169
165
# GH#22298
@@ -174,10 +170,10 @@ def test_corr_invalid_method(self):
174
170
175
171
def test_corr_int (self ):
176
172
# dtypes other than float64 GH#1761
177
- df3 = DataFrame ({"a" : [1 , 2 , 3 , 4 ], "b" : [1 , 2 , 3 , 4 ]})
173
+ df = DataFrame ({"a" : [1 , 2 , 3 , 4 ], "b" : [1 , 2 , 3 , 4 ]})
178
174
179
- df3 .cov ()
180
- df3 .corr ()
175
+ df .cov ()
176
+ df .corr ()
181
177
182
178
@td .skip_if_no_scipy
183
179
@pytest .mark .parametrize (
0 commit comments