Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
f9240f2e
Commit
f9240f2e
authored
May 23, 2020
by
jbrockmendel
Committed by
GitHub
May 24, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Follow numpy.pxd change in numpy/#16266 (GH-3630)
See
https://github.com/numpy/numpy/pull/16266
parent
a8abbdad
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
2 deletions
+91
-2
Cython/Includes/numpy/__init__.pxd
Cython/Includes/numpy/__init__.pxd
+91
-2
No files found.
Cython/Includes/numpy/__init__.pxd
View file @
f9240f2e
...
...
@@ -19,7 +19,7 @@ DEF _buffer_format_string_len = 255
cimport
cpython.buffer
as
pybuf
from
cpython.ref
cimport
Py_INCREF
from
cpython.mem
cimport
PyObject_Malloc
,
PyObject_Free
from
cpython.object
cimport
PyObject
,
PyTypeObject
from
cpython.object
cimport
PyObject
,
PyTypeObject
,
PyObject_TypeCheck
from
cpython.type
cimport
type
cimport
libc.stdio
as
stdio
...
...
@@ -228,7 +228,7 @@ cdef extern from "numpy/arrayobject.h":
cdef
int
type_num
cdef
int
itemsize
"elsize"
cdef
int
alignment
cdef
di
ct
fields
cdef
obje
ct
fields
cdef
tuple
names
# Use PyDataType_HASSUBARRAY to test whether this field is
# valid (the pointer can be NULL). Most users should access
...
...
@@ -875,6 +875,46 @@ cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset
return
f
cdef
extern
from
"numpy/ndarrayobject.h"
:
PyTypeObject
PyTimedeltaArrType_Type
PyTypeObject
PyDatetimeArrType_Type
ctypedef
int64_t
npy_timedelta
ctypedef
int64_t
npy_datetime
cdef
extern
from
"numpy/ndarraytypes.h"
:
ctypedef
struct
PyArray_DatetimeMetaData
:
NPY_DATETIMEUNIT
base
int64_t
num
cdef
extern
from
"numpy/arrayscalars.h"
:
ctypedef
struct
PyDatetimeScalarObject
:
# PyObject_HEAD
npy_datetime
obval
PyArray_DatetimeMetaData
obmeta
ctypedef
struct
PyTimedeltaScalarObject
:
# PyObject_HEAD
npy_timedelta
obval
PyArray_DatetimeMetaData
obmeta
ctypedef
enum
NPY_DATETIMEUNIT
:
NPY_FR_Y
NPY_FR_M
NPY_FR_W
NPY_FR_D
NPY_FR_B
NPY_FR_h
NPY_FR_m
NPY_FR_s
NPY_FR_ms
NPY_FR_us
NPY_FR_ns
NPY_FR_ps
NPY_FR_fs
NPY_FR_as
#
# ufunc API
#
...
...
@@ -1016,3 +1056,52 @@ cdef inline int import_ufunc() except -1:
_import_umath
()
except
Exception
:
raise
ImportError
(
"numpy.core.umath failed to import"
)
cdef
inline
bint
is_timedelta64_object
(
object
obj
):
"""
Cython equivalent of `isinstance(obj, np.timedelta64)`
Parameters
----------
obj : object
Returns
-------
bool
"""
return
PyObject_TypeCheck
(
obj
,
&
PyTimedeltaArrType_Type
)
cdef
inline
bint
is_datetime64_object
(
object
obj
):
"""
Cython equivalent of `isinstance(obj, np.datetime64)`
Parameters
----------
obj : object
Returns
-------
bool
"""
return
PyObject_TypeCheck
(
obj
,
&
PyDatetimeArrType_Type
)
cdef
inline
npy_datetime
get_datetime64_value
(
object
obj
)
nogil
:
"""
returns the int64 value underlying scalar numpy datetime64 object
Note that to interpret this as a datetime, the corresponding unit is
also needed. That can be found using `get_datetime64_unit`.
"""
return
(
<
PyDatetimeScalarObject
*>
obj
).
obval
cdef
inline
npy_timedelta
get_timedelta64_value
(
object
obj
)
nogil
:
"""
returns the int64 value underlying scalar numpy timedelta64 object
"""
return
(
<
PyTimedeltaScalarObject
*>
obj
).
obval
cdef
inline
NPY_DATETIMEUNIT
get_datetime64_unit
(
object
obj
)
nogil
:
"""
returns the unit part of the dtype for a numpy datetime64 object.
"""
return
<
NPY_DATETIMEUNIT
>
(
<
PyDatetimeScalarObject
*>
obj
).
obmeta
.
base
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment