Skip to content

Commit 863559a

Browse files
authored
Backport PR #43608: REGR: spearman corr raising on 32-bit (#43614)
1 parent 5ba7252 commit 863559a

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

doc/source/whatsnew/v1.3.4.rst

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Fixed regressions
1616
~~~~~~~~~~~~~~~~~
1717
- Fixed regression in :meth:`merge` with integer and ``NaN`` keys failing with ``outer`` merge (:issue:`43550`)
1818
- Fixed performance regression in :meth:`MultiIndex.equals` (:issue:`43549`)
19+
- Fixed regression in :meth:`DataFrame.corr` raising ``ValueError`` with ``method="spearman`` on 32-bit platforms (:issue:`43588`)
1920
-
2021

2122
.. ---------------------------------------------------------------------------

pandas/_libs/algos.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,11 @@ def nancorr_spearman(ndarray[float64_t, ndim=2] mat, Py_ssize_t minp=1) -> ndarr
389389
int64_t nobs = 0
390390
bint no_nans
391391
float64_t vx, vy, sumx, sumxx, sumyy, mean, divisor
392-
const int64_t[:] labels_n, labels_nobs
392+
const intp_t[:] labels_n, labels_nobs
393393

394394
N, K = (<object>mat).shape
395395
# For compatibility when calling rank_1d
396-
labels_n = np.zeros(N, dtype=np.int64)
396+
labels_n = np.zeros(N, dtype=np.intp)
397397

398398
# Handle the edge case where we know all results will be nan
399399
# 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
451451
with gil:
452452
# We need to slice back to nobs because rank_1d will
453453
# require arrays of nobs length
454-
labels_nobs = np.zeros(nobs, dtype=np.int64)
454+
labels_nobs = np.zeros(nobs, dtype=np.intp)
455455
rankedx = rank_1d(np.array(maskedx)[:nobs],
456456
labels=labels_nobs)
457457
rankedy = rank_1d(np.array(maskedy)[:nobs],

pandas/tests/frame/methods/test_cov_corr.py

-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ def test_corr_scipy_method(self, float_frame, method):
100100

101101
# ---------------------------------------------------------------------
102102

103-
@td.skip_if_no_scipy
104103
def test_corr_non_numeric(self, float_string_frame):
105104
# exclude non-numeric types
106105
result = float_string_frame.corr()
@@ -125,11 +124,9 @@ def test_corr_nooverlap(self, meth):
125124
assert rs.loc["B", "B"] == 1
126125
assert isna(rs.loc["C", "C"])
127126

128-
@td.skip_if_no_scipy
129127
@pytest.mark.parametrize("meth", ["pearson", "spearman"])
130128
def test_corr_constant(self, meth):
131129
# constant --> all NA
132-
133130
df = DataFrame(
134131
{
135132
"A": [1, 1, 1, np.nan, np.nan, np.nan],

0 commit comments

Comments
 (0)