-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c1e37b0
remove ctypedef class from lib.pyx
WillAyd fd0ce1f
fixes
WillAyd 12f4194
try something for bytes
WillAyd db1ebbd
feedback
WillAyd 332546a
Merge branch 'main' into lib-cleanup
WillAyd d667653
fix comparisons
WillAyd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,22 +73,6 @@ cdef extern from "Python.h": | |
bint PyObject_TypeCheck(object obj, PyTypeObject* type) nogil | ||
|
||
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 | ||
|
||
PyTypeObject PySignedIntegerArrType_Type | ||
PyTypeObject PyUnsignedIntegerArrType_Type | ||
|
||
|
@@ -1746,10 +1730,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 | ||
|
@@ -1830,7 +1814,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): | ||
|
@@ -1847,7 +1831,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 | ||
|
@@ -1879,7 +1863,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): | ||
|
@@ -1896,7 +1880,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 | ||
|
@@ -1915,7 +1899,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): | ||
|
@@ -1944,7 +1928,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 cnp.PyDataType_ISSTRING(self.dtype) | ||
|
||
|
||
cpdef bint is_string_array(ndarray values, bint skipna=False): | ||
|
@@ -1961,7 +1945,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 == cnp.NPY_BYTE or self.dtype.type == cnp.NPY_UBYTE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @seberg is this the right way to check for bytes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, its |
||
|
||
|
||
cdef bint is_bytes_array(ndarray values, bint skipna=False): | ||
|
@@ -1976,7 +1960,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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is also wrong,
ISSTRING
checks for bytes (NPY_STRING) OR unicode. You want== NPY_UNICODE
here if you use this.