diff --git a/doc/source/whatsnew/v1.3.4.rst b/doc/source/whatsnew/v1.3.4.rst index 9387483bd62f5..4bbd44b395a35 100644 --- a/doc/source/whatsnew/v1.3.4.rst +++ b/doc/source/whatsnew/v1.3.4.rst @@ -16,6 +16,7 @@ Fixed regressions ~~~~~~~~~~~~~~~~~ - Fixed regression in :meth:`merge` with integer and ``NaN`` keys failing with ``outer`` merge (:issue:`43550`) - Fixed performance regression in :meth:`MultiIndex.equals` (:issue:`43549`) +- Fixed regression in :meth:`DataFrame.corr` raising ``ValueError`` with ``method="spearman`` on 32-bit platforms (:issue:`43588`) - .. --------------------------------------------------------------------------- diff --git a/pandas/_libs/algos.pyx b/pandas/_libs/algos.pyx index f619f09f85e66..d574df772d7e2 100644 --- a/pandas/_libs/algos.pyx +++ b/pandas/_libs/algos.pyx @@ -389,11 +389,11 @@ def nancorr_spearman(ndarray[float64_t, ndim=2] mat, Py_ssize_t minp=1) -> ndarr int64_t nobs = 0 bint no_nans float64_t vx, vy, sumx, sumxx, sumyy, mean, divisor - const int64_t[:] labels_n, labels_nobs + const intp_t[:] labels_n, labels_nobs N, K = (mat).shape # For compatibility when calling rank_1d - labels_n = np.zeros(N, dtype=np.int64) + labels_n = np.zeros(N, dtype=np.intp) # Handle the edge case where we know all results will be nan # to keep conditional logic inside loop simpler @@ -451,7 +451,7 @@ def nancorr_spearman(ndarray[float64_t, ndim=2] mat, Py_ssize_t minp=1) -> ndarr with gil: # We need to slice back to nobs because rank_1d will # require arrays of nobs length - labels_nobs = np.zeros(nobs, dtype=np.int64) + labels_nobs = np.zeros(nobs, dtype=np.intp) rankedx = rank_1d(np.array(maskedx)[:nobs], labels=labels_nobs) rankedy = rank_1d(np.array(maskedy)[:nobs], diff --git a/pandas/tests/frame/methods/test_cov_corr.py b/pandas/tests/frame/methods/test_cov_corr.py index c259902ec2498..3dbf49df72558 100644 --- a/pandas/tests/frame/methods/test_cov_corr.py +++ b/pandas/tests/frame/methods/test_cov_corr.py @@ -100,7 +100,6 @@ def test_corr_scipy_method(self, float_frame, method): # --------------------------------------------------------------------- - @td.skip_if_no_scipy def test_corr_non_numeric(self, float_string_frame): # exclude non-numeric types result = float_string_frame.corr() @@ -125,11 +124,9 @@ def test_corr_nooverlap(self, meth): assert rs.loc["B", "B"] == 1 assert isna(rs.loc["C", "C"]) - @td.skip_if_no_scipy @pytest.mark.parametrize("meth", ["pearson", "spearman"]) def test_corr_constant(self, meth): # constant --> all NA - df = DataFrame( { "A": [1, 1, 1, np.nan, np.nan, np.nan],