diff --git a/pandas/tests/frame/methods/test_cov_corr.py b/pandas/tests/frame/methods/test_cov_corr.py index 3da3d82ec77f9..9a67360e9b11a 100644 --- a/pandas/tests/frame/methods/test_cov_corr.py +++ b/pandas/tests/frame/methods/test_cov_corr.py @@ -29,17 +29,16 @@ def test_cov(self, float_frame, float_string_frame): frame = float_frame.copy() frame["A"][:5] = np.nan frame["B"][5:10] = np.nan - result = float_frame.cov(min_periods=len(float_frame) - 8) - expected = float_frame.cov() + result = frame.cov(min_periods=len(frame) - 8) + expected = frame.cov() expected.loc["A", "B"] = np.nan expected.loc["B", "A"] = np.nan + tm.assert_frame_equal(result, expected) # regular - float_frame["A"][:5] = np.nan - float_frame["B"][:10] = np.nan - cov = float_frame.cov() - - tm.assert_almost_equal(cov["A"]["C"], float_frame["A"].cov(float_frame["C"])) + result = frame.cov() + expected = frame["A"].cov(frame["C"]) + tm.assert_almost_equal(result["A"]["C"], expected) # exclude non-numeric types result = float_string_frame.cov() @@ -101,10 +100,7 @@ def test_corr_scipy_method(self, float_frame, method): # --------------------------------------------------------------------- @td.skip_if_no_scipy - def test_corr_non_numeric(self, float_frame, float_string_frame): - float_frame["A"][:5] = np.nan - float_frame["B"][5:10] = np.nan - + def test_corr_non_numeric(self, float_string_frame): # exclude non-numeric types result = float_string_frame.corr() expected = float_string_frame.loc[:, ["A", "B", "C", "D"]].corr() @@ -143,27 +139,27 @@ def test_corr_constant(self, meth): assert isna(rs.values).all() @td.skip_if_no_scipy - def test_corr_int_and_boolean(self): + @pytest.mark.parametrize("meth", ["pearson", "kendall", "spearman"]) + def test_corr_int_and_boolean(self, meth): # when dtypes of pandas series are different # then ndarray will have dtype=object, # so it need to be properly handled df = DataFrame({"a": [True, False], "b": [1, 0]}) expected = DataFrame(np.ones((2, 2)), index=["a", "b"], columns=["a", "b"]) - for meth in ["pearson", "kendall", "spearman"]: - with warnings.catch_warnings(record=True): - warnings.simplefilter("ignore", RuntimeWarning) - result = df.corr(meth) - tm.assert_frame_equal(result, expected) + with warnings.catch_warnings(record=True): + warnings.simplefilter("ignore", RuntimeWarning) + result = df.corr(meth) + tm.assert_frame_equal(result, expected) - def test_corr_cov_independent_index_column(self): + @pytest.mark.parametrize("method", ["cov", "corr"]) + def test_corr_cov_independent_index_column(self, method): # GH#14617 df = DataFrame(np.random.randn(4 * 10).reshape(10, 4), columns=list("abcd")) - for method in ["cov", "corr"]: - result = getattr(df, method)() - assert result.index is not result.columns - assert result.index.equals(result.columns) + result = getattr(df, method)() + assert result.index is not result.columns + assert result.index.equals(result.columns) def test_corr_invalid_method(self): # GH#22298 @@ -174,10 +170,10 @@ def test_corr_invalid_method(self): def test_corr_int(self): # dtypes other than float64 GH#1761 - df3 = DataFrame({"a": [1, 2, 3, 4], "b": [1, 2, 3, 4]}) + df = DataFrame({"a": [1, 2, 3, 4], "b": [1, 2, 3, 4]}) - df3.cov() - df3.corr() + df.cov() + df.corr() @td.skip_if_no_scipy @pytest.mark.parametrize(