diff options
-rw-r--r-- | numpy/__init__.cython-30.pxd | 23 | ||||
-rw-r--r-- | numpy/__init__.pxd | 23 | ||||
-rw-r--r-- | numpy/core/tests/examples/checks.pyx | 4 | ||||
-rw-r--r-- | numpy/core/tests/test_cython.py | 8 |
4 files changed, 58 insertions, 0 deletions
diff --git a/numpy/__init__.cython-30.pxd b/numpy/__init__.cython-30.pxd index 4d9ec1fed..a2c451bc1 100644 --- a/numpy/__init__.cython-30.pxd +++ b/numpy/__init__.cython-30.pxd @@ -808,6 +808,29 @@ cdef extern from "numpy/ndarraytypes.h": int64_t num cdef extern from "numpy/arrayscalars.h": + + # abstract types + ctypedef class numpy.generic [object PyObject]: + pass + ctypedef class numpy.number [object PyObject]: + pass + ctypedef class numpy.integer [object PyObject]: + pass + ctypedef class numpy.signedinteger [object PyObject]: + pass + ctypedef class numpy.unsignedinteger [object PyObject]: + pass + ctypedef class numpy.inexact [object PyObject]: + pass + ctypedef class numpy.floating [object PyObject]: + pass + ctypedef class numpy.complexfloating [object PyObject]: + pass + ctypedef class numpy.flexible [object PyObject]: + pass + ctypedef class numpy.character [object PyObject]: + pass + ctypedef struct PyDatetimeScalarObject: # PyObject_HEAD npy_datetime obval diff --git a/numpy/__init__.pxd b/numpy/__init__.pxd index bf4298e59..fd704b7e3 100644 --- a/numpy/__init__.pxd +++ b/numpy/__init__.pxd @@ -766,6 +766,29 @@ cdef extern from "numpy/ndarraytypes.h": int64_t num cdef extern from "numpy/arrayscalars.h": + + # abstract types + ctypedef class numpy.generic [object PyObject]: + pass + ctypedef class numpy.number [object PyObject]: + pass + ctypedef class numpy.integer [object PyObject]: + pass + ctypedef class numpy.signedinteger [object PyObject]: + pass + ctypedef class numpy.unsignedinteger [object PyObject]: + pass + ctypedef class numpy.inexact [object PyObject]: + pass + ctypedef class numpy.floating [object PyObject]: + pass + ctypedef class numpy.complexfloating [object PyObject]: + pass + ctypedef class numpy.flexible [object PyObject]: + pass + ctypedef class numpy.character [object PyObject]: + pass + ctypedef struct PyDatetimeScalarObject: # PyObject_HEAD npy_datetime obval diff --git a/numpy/core/tests/examples/checks.pyx b/numpy/core/tests/examples/checks.pyx index ecf0ad3fa..151979db7 100644 --- a/numpy/core/tests/examples/checks.pyx +++ b/numpy/core/tests/examples/checks.pyx @@ -24,3 +24,7 @@ def get_td64_value(obj): def get_dt64_unit(obj): return cnp.get_datetime64_unit(obj) + + +def is_integer(obj): + return isinstance(obj, (cnp.integer, int)) diff --git a/numpy/core/tests/test_cython.py b/numpy/core/tests/test_cython.py index 63524b269..bfdb692d7 100644 --- a/numpy/core/tests/test_cython.py +++ b/numpy/core/tests/test_cython.py @@ -126,3 +126,11 @@ def test_get_datetime64_unit(install_temp): result = checks.get_dt64_unit(td64) expected = 5 assert result == expected + + +def test_abstract_scalars(install_temp): + import checks + + assert checks.is_integer(1) + assert checks.is_integer(np.int8(1)) + assert checks.is_integer(np.uint64(1)) |