Skip to content

Commit 5122e68

Browse files
authored
Remove GIL from take_2d_axis_0 (pandas-dev#54483)
1 parent 70cd5c0 commit 5122e68

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

pandas/_libs/algos_take_helper.pxi.in

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,30 @@ def take_2d_axis0_{{name}}_{{dest}}(ndarray[{{c_type_in}}, ndim=2] values,
121121

122122
{{if c_type_in == c_type_out != "object"}}
123123
# GH#3130
124-
if (values.strides[1] == out.strides[1] and
125-
values.strides[1] == sizeof({{c_type_out}}) and
126-
sizeof({{c_type_out}}) * n >= 256):
127-
128-
for i in range(n):
129-
idx = indexer[i]
130-
if idx == -1:
131-
for j in range(k):
132-
out[i, j] = fv
133-
else:
134-
v = &values[idx, 0]
135-
o = &out[i, 0]
136-
memmove(o, v, <size_t>(sizeof({{c_type_out}}) * k))
137-
return
138-
{{endif}}
124+
with nogil:
125+
if (values.strides[1] == out.strides[1] and
126+
values.strides[1] == sizeof({{c_type_out}}) and
127+
sizeof({{c_type_out}}) * n >= 256):
128+
129+
for i in range(n):
130+
idx = indexer[i]
131+
if idx == -1:
132+
for j in range(k):
133+
out[i, j] = fv
134+
else:
135+
v = &values[idx, 0]
136+
o = &out[i, 0]
137+
memmove(o, v, <size_t>(sizeof({{c_type_out}}) * k))
138+
else:
139+
for i in range(n):
140+
idx = indexer[i]
141+
if idx == -1:
142+
for j in range(k):
143+
out[i, j] = fv
144+
else:
145+
for j in range(k):
146+
out[i, j] = values[idx, j]
147+
{{else}}
139148

140149
for i in range(n):
141150
idx = indexer[i]
@@ -149,6 +158,7 @@ def take_2d_axis0_{{name}}_{{dest}}(ndarray[{{c_type_in}}, ndim=2] values,
149158
{{else}}
150159
out[i, j] = values[idx, j]
151160
{{endif}}
161+
{{endif}}
152162

153163

154164
@cython.wraparound(False)

0 commit comments

Comments
 (0)