Skip to content

Commit 4c82b17

Browse files
committed
add more conditional nogil
1 parent f18ac8d commit 4c82b17

File tree

3 files changed

+3
-62
lines changed

3 files changed

+3
-62
lines changed

pandas/_libs/algos.pyx

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -818,33 +818,7 @@ def is_monotonic(const numeric_object_t[:] arr, bint timelike):
818818
if timelike and <int64_t>arr[0] == NPY_NAT:
819819
return False, False, False
820820

821-
if numeric_object_t is not object:
822-
with nogil:
823-
prev = arr[0]
824-
for i in range(1, n):
825-
cur = arr[i]
826-
if timelike and <int64_t>cur == NPY_NAT:
827-
is_monotonic_inc = 0
828-
is_monotonic_dec = 0
829-
break
830-
if cur < prev:
831-
is_monotonic_inc = 0
832-
elif cur > prev:
833-
is_monotonic_dec = 0
834-
elif cur == prev:
835-
is_unique = 0
836-
else:
837-
# cur or prev is NaN
838-
is_monotonic_inc = 0
839-
is_monotonic_dec = 0
840-
break
841-
if not is_monotonic_inc and not is_monotonic_dec:
842-
is_monotonic_inc = 0
843-
is_monotonic_dec = 0
844-
break
845-
prev = cur
846-
else:
847-
# object-dtype, identical to above except we cannot use `with nogil`
821+
with nogil(numeric_object_t is not object):
848822
prev = arr[0]
849823
for i in range(1, n):
850824
cur = arr[i]

pandas/_libs/hashtable_func_helper.pxi.in

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -415,20 +415,7 @@ def mode(ndarray[htfunc_t] values, bint dropna, const uint8_t[:] mask=None):
415415

416416
modes = np.empty(nkeys, dtype=values.dtype)
417417

418-
if htfunc_t is not object:
419-
with nogil:
420-
for k in range(nkeys):
421-
count = counts[k]
422-
if count == max_count:
423-
j += 1
424-
elif count > max_count:
425-
max_count = count
426-
j = 0
427-
else:
428-
continue
429-
430-
modes[j] = keys[k]
431-
else:
418+
with nogil(htfunc_t is not object):
432419
for k in range(nkeys):
433420
count = counts[k]
434421
if count == max_count:

pandas/_libs/reshape.pyx

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,7 @@ def unstack(const numeric_object_t[:, :] values, const uint8_t[:] mask,
4040
cdef:
4141
Py_ssize_t i, j, w, nulls, s, offset
4242

43-
if numeric_object_t is not object:
44-
# evaluated at compile-time
45-
with nogil:
46-
for i in range(stride):
47-
48-
nulls = 0
49-
for j in range(length):
50-
51-
for w in range(width):
52-
53-
offset = j * width + w
54-
55-
if mask[offset]:
56-
s = i * width + w
57-
new_values[j, s] = values[offset - nulls, i]
58-
new_mask[j, s] = 1
59-
else:
60-
nulls += 1
61-
62-
else:
63-
# object-dtype, identical to above but we cannot use nogil
43+
with nogil(numeric_object_t is not object):
6444
for i in range(stride):
6545

6646
nulls = 0

0 commit comments

Comments
 (0)