diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 2d181e826c2a9..839f56db2365e 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -7975,7 +7975,7 @@ def corr(self, method="pearson", min_periods=1) -> "DataFrame": numeric_df = self._get_numeric_data() cols = numeric_df.columns idx = cols.copy() - mat = numeric_df.astype(float, copy=False).to_numpy() + mat = numeric_df.to_numpy(dtype=float, na_value=np.nan, copy=False) if method == "pearson": correl = libalgos.nancorr(mat, minp=min_periods) @@ -8110,7 +8110,7 @@ def cov(self, min_periods=None) -> "DataFrame": numeric_df = self._get_numeric_data() cols = numeric_df.columns idx = cols.copy() - mat = numeric_df.astype(float, copy=False).to_numpy() + mat = numeric_df.to_numpy(dtype=float, na_value=np.nan, copy=False) if notna(mat).all(): if min_periods is not None and min_periods > len(mat):