Skip to content

remove ctypedef class from lib.pyx #56018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 10 additions & 27 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,6 @@ from numpy cimport (
cnp.import_array()


cdef extern from "numpy/arrayobject.h":
# cython's numpy.dtype specification is incorrect, which leads to
# errors in issubclass(self.dtype.type, np.bool_), so we directly
# include the correct version
# https://github.com/cython/cython/issues/2022

ctypedef class numpy.dtype [object PyArray_Descr]:
# Use PyDataType_* macros when possible, however there are no macros
# for accessing some of the fields, so some are defined. Please
# ask on cython-dev if you need more.
cdef:
int type_num
int itemsize "elsize"
char byteorder
object fields
tuple names

cdef extern from "pandas/parser/pd_parser.h":
int floatify(object, float64_t *result, int *maybe_int) except -1
void PandasParser_IMPORT()
Expand Down Expand Up @@ -1736,10 +1719,10 @@ cdef class Validator:

cdef:
Py_ssize_t n
dtype dtype
cnp.dtype dtype
bint skipna

def __cinit__(self, Py_ssize_t n, dtype dtype=np.dtype(np.object_),
def __cinit__(self, Py_ssize_t n, cnp.dtype dtype=np.dtype(np.object_),
bint skipna=False):
self.n = n
self.dtype = dtype
Expand Down Expand Up @@ -1820,7 +1803,7 @@ cdef class BoolValidator(Validator):
return util.is_bool_object(value)

cdef bint is_array_typed(self) except -1:
return issubclass(self.dtype.type, np.bool_)
return cnp.PyDataType_ISBOOL(self.dtype)


cpdef bint is_bool_array(ndarray values, bint skipna=False):
Expand All @@ -1837,7 +1820,7 @@ cdef class IntegerValidator(Validator):
return util.is_integer_object(value)

cdef bint is_array_typed(self) except -1:
return issubclass(self.dtype.type, np.integer)
return cnp.PyDataType_ISINTEGER(self.dtype)


# Note: only python-exposed for tests
Expand Down Expand Up @@ -1869,7 +1852,7 @@ cdef class IntegerFloatValidator(Validator):
return util.is_integer_object(value) or util.is_float_object(value)

cdef bint is_array_typed(self) except -1:
return issubclass(self.dtype.type, np.integer)
return cnp.PyDataType_ISINTEGER(self.dtype)


cdef bint is_integer_float_array(ndarray values, bint skipna=True):
Expand All @@ -1886,7 +1869,7 @@ cdef class FloatValidator(Validator):
return util.is_float_object(value)

cdef bint is_array_typed(self) except -1:
return issubclass(self.dtype.type, np.floating)
return cnp.PyDataType_ISFLOAT(self.dtype)


# Note: only python-exposed for tests
Expand All @@ -1905,7 +1888,7 @@ cdef class ComplexValidator(Validator):
)

cdef bint is_array_typed(self) except -1:
return issubclass(self.dtype.type, np.complexfloating)
return cnp.PyDataType_ISCOMPLEX(self.dtype)


cdef bint is_complex_array(ndarray values):
Expand Down Expand Up @@ -1934,7 +1917,7 @@ cdef class StringValidator(Validator):
return isinstance(value, str)

cdef bint is_array_typed(self) except -1:
return issubclass(self.dtype.type, np.str_)
return self.dtype.type_num == cnp.NPY_UNICODE


cpdef bint is_string_array(ndarray values, bint skipna=False):
Expand All @@ -1951,7 +1934,7 @@ cdef class BytesValidator(Validator):
return isinstance(value, bytes)

cdef bint is_array_typed(self) except -1:
return issubclass(self.dtype.type, np.bytes_)
return self.dtype.type_num == cnp.NPY_STRING


cdef bint is_bytes_array(ndarray values, bint skipna=False):
Expand All @@ -1966,7 +1949,7 @@ cdef class TemporalValidator(Validator):
cdef:
bint all_generic_na

def __cinit__(self, Py_ssize_t n, dtype dtype=np.dtype(np.object_),
def __cinit__(self, Py_ssize_t n, cnp.dtype dtype=np.dtype(np.object_),
bint skipna=False):
self.n = n
self.dtype = dtype
Expand Down