Skip to content

Commit fce14ce

Browse files
ShaharNavehSeeminSyed
authored andcommitted
PERF: Using Numpy C-API arange (pandas-dev#32681)
1 parent 366c8e5 commit fce14ce

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pandas/_libs/internals.pyx

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ cdef extern from "Python.h":
77
Py_ssize_t PY_SSIZE_T_MAX
88

99
import numpy as np
10-
from numpy cimport int64_t
10+
cimport numpy as cnp
11+
from numpy cimport NPY_INT64, int64_t
12+
cnp.import_array()
1113

1214
from pandas._libs.algos import ensure_int64
1315

@@ -105,7 +107,9 @@ cdef class BlockPlacement:
105107
Py_ssize_t start, stop, end, _
106108
if not self._has_array:
107109
start, stop, step, _ = slice_get_indices_ex(self._as_slice)
108-
self._as_array = np.arange(start, stop, step, dtype=np.int64)
110+
# NOTE: this is the C-optimized equivalent of
111+
# np.arange(start, stop, step, dtype=np.int64)
112+
self._as_array = cnp.PyArray_Arange(start, stop, step, NPY_INT64)
109113
self._has_array = True
110114
return self._as_array
111115

0 commit comments

Comments
 (0)