Skip to content

Commit cde6508

Browse files
committed
release gil in groupby
1 parent c218df6 commit cde6508

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

pandas/_libs/groupby.pyx

+26-25
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ def group_cumsum(numeric_t[:, ::1] out,
279279
elif numeric_t == float64_t:
280280
if (val == MAXfloat64) or (val == MINfloat64):
281281
if (t == MAXfloat64) or (t == MINfloat64):
282+
val = t
282283
out[i, j] = val
283284
accum[lab, j] = val
284285
break
@@ -579,34 +580,34 @@ def group_add(add_t[:, ::1] out,
579580
else:
580581
out[i, j] = sumx[i, j]
581582
else:
582-
for i in range(N):
583-
lab = labels[i]
584-
if lab < 0:
585-
continue
583+
with nogil:
584+
for i in range(N):
585+
lab = labels[i]
586+
if lab < 0:
587+
continue
586588

587-
counts[lab] += 1
588-
for j in range(K):
589-
val = values[i, j]
589+
counts[lab] += 1
590+
for j in range(K):
591+
val = values[i, j]
590592

591-
# todo: using np.isinf not possible without gil, find other
592-
# function to release gil for the whole block
593-
if np.isinf(val):
594-
sumx[lab, j] = val
595-
break
596-
# not nan
597-
if val == val:
598-
nobs[lab, j] += 1
599-
y = val - compensation[lab, j]
600-
t = sumx[lab, j] + y
601-
compensation[lab, j] = t - sumx[lab, j] - y
602-
sumx[lab, j] = t
593+
# function to release gil for the whole block
594+
if (val == MAXfloat64) or (val == MINfloat64):
595+
sumx[lab, j] = val
596+
break
597+
# not nan
598+
if val == val:
599+
nobs[lab, j] += 1
600+
y = val - compensation[lab, j]
601+
t = sumx[lab, j] + y
602+
compensation[lab, j] = t - sumx[lab, j] - y
603+
sumx[lab, j] = t
603604

604-
for i in range(ncounts):
605-
for j in range(K):
606-
if nobs[i, j] < min_count:
607-
out[i, j] = NAN
608-
else:
609-
out[i, j] = sumx[i, j]
605+
for i in range(ncounts):
606+
for j in range(K):
607+
if nobs[i, j] < min_count:
608+
out[i, j] = NAN
609+
else:
610+
out[i, j] = sumx[i, j]
610611

611612

612613
@cython.wraparound(False)

0 commit comments

Comments
 (0)