Skip to content

Commit 08d8e39

Browse files
author
Daniel Saxton
committed
Check for same missing pattern
1 parent 9f8e3cf commit 08d8e39

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pandas/_libs/algos.pyx

+7
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,9 @@ def nancorr_spearman(const float64_t[:, :] mat, Py_ssize_t minp=1):
316316
for xi in range(K):
317317
for yi in range(xi + 1):
318318
nobs = 0
319+
same_miss_pat = True
319320
for i in range(N):
321+
same_miss_pat &= not (mask[i, xi] ^ mask[i, yi])
320322
if mask[i, xi] and mask[i, yi]:
321323
nobs += 1
322324

@@ -326,12 +328,17 @@ def nancorr_spearman(const float64_t[:, :] mat, Py_ssize_t minp=1):
326328
maskedx = np.empty(nobs, dtype=np.float64)
327329
maskedy = np.empty(nobs, dtype=np.float64)
328330
j = 0
331+
329332
for i in range(N):
330333
if mask[i, xi] and mask[i, yi]:
331334
maskedx[j] = ranked_mat[i, xi]
332335
maskedy[j] = ranked_mat[i, yi]
333336
j += 1
334337

338+
if not same_miss_pat:
339+
maskedx = rank_1d_float64(maskedx)
340+
maskedy = rank_1d_float64(maskedy)
341+
335342
mean = (nobs + 1) / 2.
336343

337344
# now the cov numerator

0 commit comments

Comments
 (0)