@@ -67,23 +67,6 @@ from numpy cimport (
67
67
cnp.import_array()
68
68
69
69
70
- cdef extern from " numpy/arrayobject.h" :
71
- # cython's numpy.dtype specification is incorrect, which leads to
72
- # errors in issubclass(self.dtype.type, np.bool_), so we directly
73
- # include the correct version
74
- # https://github.com/cython/cython/issues/2022
75
-
76
- ctypedef class numpy.dtype [object PyArray_Descr]:
77
- # Use PyDataType_* macros when possible, however there are no macros
78
- # for accessing some of the fields, so some are defined. Please
79
- # ask on cython-dev if you need more.
80
- cdef:
81
- int type_num
82
- int itemsize " elsize"
83
- char byteorder
84
- object fields
85
- tuple names
86
-
87
70
cdef extern from " pandas/parser/pd_parser.h" :
88
71
int floatify(object , float64_t * result, int * maybe_int) except - 1
89
72
void PandasParser_IMPORT()
@@ -1735,10 +1718,10 @@ cdef class Validator:
1735
1718
1736
1719
cdef:
1737
1720
Py_ssize_t n
1738
- dtype dtype
1721
+ cnp. dtype dtype
1739
1722
bint skipna
1740
1723
1741
- def __cinit__ (self , Py_ssize_t n , dtype dtype = np.dtype(np.object_),
1724
+ def __cinit__ (self , Py_ssize_t n , cnp. dtype dtype = np.dtype(np.object_),
1742
1725
bint skipna = False ):
1743
1726
self .n = n
1744
1727
self .dtype = dtype
@@ -1819,7 +1802,7 @@ cdef class BoolValidator(Validator):
1819
1802
return util.is_bool_object(value)
1820
1803
1821
1804
cdef bint is_array_typed(self ) except - 1 :
1822
- return issubclass (self .dtype.type, np.bool_ )
1805
+ return cnp.PyDataType_ISBOOL (self .dtype)
1823
1806
1824
1807
1825
1808
cpdef bint is_bool_array(ndarray values, bint skipna = False ):
@@ -1836,7 +1819,7 @@ cdef class IntegerValidator(Validator):
1836
1819
return util.is_integer_object(value)
1837
1820
1838
1821
cdef bint is_array_typed(self ) except - 1 :
1839
- return issubclass (self .dtype.type, np.integer )
1822
+ return cnp.PyDataType_ISINTEGER (self .dtype)
1840
1823
1841
1824
1842
1825
# Note: only python-exposed for tests
@@ -1868,7 +1851,7 @@ cdef class IntegerFloatValidator(Validator):
1868
1851
return util.is_integer_object(value) or util.is_float_object(value)
1869
1852
1870
1853
cdef bint is_array_typed(self ) except - 1 :
1871
- return issubclass (self .dtype.type, np.integer )
1854
+ return cnp.PyDataType_ISINTEGER (self .dtype)
1872
1855
1873
1856
1874
1857
cdef bint is_integer_float_array(ndarray values, bint skipna = True ):
@@ -1885,7 +1868,7 @@ cdef class FloatValidator(Validator):
1885
1868
return util.is_float_object(value)
1886
1869
1887
1870
cdef bint is_array_typed(self ) except - 1 :
1888
- return issubclass (self .dtype.type, np.floating )
1871
+ return cnp.PyDataType_ISFLOAT (self .dtype)
1889
1872
1890
1873
1891
1874
# Note: only python-exposed for tests
@@ -1904,7 +1887,7 @@ cdef class ComplexValidator(Validator):
1904
1887
)
1905
1888
1906
1889
cdef bint is_array_typed(self ) except - 1 :
1907
- return issubclass (self .dtype.type, np.complexfloating )
1890
+ return cnp.PyDataType_ISCOMPLEX (self .dtype)
1908
1891
1909
1892
1910
1893
cdef bint is_complex_array(ndarray values):
@@ -1933,7 +1916,7 @@ cdef class StringValidator(Validator):
1933
1916
return isinstance (value, str )
1934
1917
1935
1918
cdef bint is_array_typed(self ) except - 1 :
1936
- return issubclass ( self .dtype.type, np.str_)
1919
+ return self .dtype.type_num == cnp.NPY_UNICODE
1937
1920
1938
1921
1939
1922
cpdef bint is_string_array(ndarray values, bint skipna = False ):
@@ -1950,7 +1933,7 @@ cdef class BytesValidator(Validator):
1950
1933
return isinstance (value, bytes)
1951
1934
1952
1935
cdef bint is_array_typed(self ) except - 1 :
1953
- return issubclass ( self .dtype.type, np.bytes_)
1936
+ return self .dtype.type_num == cnp.NPY_STRING
1954
1937
1955
1938
1956
1939
cdef bint is_bytes_array(ndarray values, bint skipna = False ):
@@ -1965,7 +1948,7 @@ cdef class TemporalValidator(Validator):
1965
1948
cdef:
1966
1949
bint all_generic_na
1967
1950
1968
- def __cinit__ (self , Py_ssize_t n , dtype dtype = np.dtype(np.object_),
1951
+ def __cinit__ (self , Py_ssize_t n , cnp. dtype dtype = np.dtype(np.object_),
1969
1952
bint skipna = False ):
1970
1953
self .n = n
1971
1954
self .dtype = dtype
0 commit comments