Skip to content

Commit 0a94cca

Browse files
committed
Cleanup leftover cimport, use c-api funcs for isinstance
1 parent 3fb0d0a commit 0a94cca

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

pandas/_libs/internals.pyx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
cimport cython
44
from cython cimport Py_ssize_t
55

6-
from cpython cimport PyObject
6+
from cpython cimport PyObject, PyInt_Check
7+
from cpython.slice cimport PySlice_Check
78

89
import numpy as np
910
cimport numpy as np
@@ -33,7 +34,7 @@ cdef class BlockPlacement:
3334
self._has_slice = False
3435
self._has_array = False
3536

36-
if isinstance(val, slice):
37+
if PySlice_Check(val):
3738
slc = slice_canonize(val)
3839

3940
if slc.start != slc.stop:
@@ -127,7 +128,7 @@ cdef class BlockPlacement:
127128
else:
128129
val = self._as_array[loc]
129130

130-
if not isinstance(val, slice) and val.ndim == 0:
131+
if not PySlice_Check(val) and val.ndim == 0:
131132
return val
132133

133134
return BlockPlacement(val)
@@ -147,7 +148,7 @@ cdef class BlockPlacement:
147148
slice s = self._ensure_has_slice()
148149
Py_ssize_t other_int, start, stop, step, l
149150

150-
if isinstance(other, int) and s is not None:
151+
if PyInt_Check(other) and s is not None:
151152
other_int = <Py_ssize_t>other
152153

153154
if other_int == 0:
@@ -299,7 +300,7 @@ cdef slice_getitem(slice slc, ind):
299300

300301
s_start, s_stop, s_step, s_len = slice_get_indices_ex(slc)
301302

302-
if isinstance(ind, slice):
303+
if PySlice_Check(ind):
303304
ind_start, ind_stop, ind_step, ind_len = slice_get_indices_ex(ind,
304305
s_len)
305306

pandas/_libs/lib.pyx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ try:
3535
except ImportError:
3636
from cpython cimport PyUnicode_GET_SIZE as PyString_GET_SIZE
3737

38-
cdef extern from "compat_helper.h":
39-
40-
cdef int slice_get_indices(
41-
PyObject* s, Py_ssize_t length,
42-
Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step,
43-
Py_ssize_t *slicelength) except -1
44-
4538
cimport cpython
4639

4740
isnan = np.isnan

0 commit comments

Comments
 (0)