forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnp_datetime.pxd
140 lines (114 loc) · 3.94 KB
/
np_datetime.pxd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
cimport numpy as cnp
from cpython.datetime cimport (
date,
datetime,
)
from numpy cimport (
int32_t,
int64_t,
)
# TODO(cython3): most of these can be cimported directly from numpy
cdef extern from "numpy/ndarrayobject.h":
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
cdef extern from "numpy/ndarraytypes.h":
ctypedef struct npy_datetimestruct:
int64_t year
int32_t month, day, hour, min, sec, us, ps, as
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
NPY_FR_GENERIC
int64_t NPY_DATETIME_NAT # elswhere we call this NPY_NAT
cdef extern from "src/datetime/pd_datetime.h":
ctypedef struct pandas_timedeltastruct:
int64_t days
int32_t hrs, min, sec, ms, us, ns, seconds, microseconds, nanoseconds
void pandas_datetime_to_datetimestruct(npy_datetime val,
NPY_DATETIMEUNIT fr,
npy_datetimestruct *result) nogil
npy_datetime npy_datetimestruct_to_datetime(NPY_DATETIMEUNIT fr,
npy_datetimestruct *d) nogil
void pandas_timedelta_to_timedeltastruct(npy_timedelta val,
NPY_DATETIMEUNIT fr,
pandas_timedeltastruct *result
) nogil
Py_hash_t hash_datetime_from_struct(npy_datetimestruct* dts) except? -1
void PandasDateTime_IMPORT()
ctypedef enum FormatRequirement:
PARTIAL_MATCH
EXACT_MATCH
INFER_FORMAT
# You must call this before using the PandasDateTime CAPI functions
cdef inline void import_pandas_datetime():
PandasDateTime_IMPORT
cdef bint cmp_scalar(int64_t lhs, int64_t rhs, int op) except -1
cdef check_dts_bounds(npy_datetimestruct *dts, NPY_DATETIMEUNIT unit=?)
cdef int64_t pydatetime_to_dt64(
datetime val, npy_datetimestruct *dts, NPY_DATETIMEUNIT reso=?
)
cdef void pydatetime_to_dtstruct(datetime dt, npy_datetimestruct *dts)
cdef int64_t pydate_to_dt64(
date val, npy_datetimestruct *dts, NPY_DATETIMEUNIT reso=?
)
cdef void pydate_to_dtstruct(date val, npy_datetimestruct *dts)
cdef npy_datetime get_datetime64_value(object obj) nogil
cdef npy_timedelta get_timedelta64_value(object obj) nogil
cdef NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil
cdef int string_to_dts(
str val,
npy_datetimestruct* dts,
NPY_DATETIMEUNIT* out_bestunit,
int* out_local,
int* out_tzoffset,
bint want_exc,
format: str | None = *,
bint exact = *
) except? -1
cdef NPY_DATETIMEUNIT get_unit_from_dtype(cnp.dtype dtype)
cpdef cnp.ndarray astype_overflowsafe(
cnp.ndarray values, # ndarray[datetime64[anyunit]]
cnp.dtype dtype, # ndarray[datetime64[anyunit]]
bint copy=*,
bint round_ok=*,
bint is_coerce=*,
)
cdef int64_t get_conversion_factor(
NPY_DATETIMEUNIT from_unit,
NPY_DATETIMEUNIT to_unit,
) except? -1
cdef bint cmp_dtstructs(npy_datetimestruct* left, npy_datetimestruct* right, int op)
cdef get_implementation_bounds(
NPY_DATETIMEUNIT reso, npy_datetimestruct *lower, npy_datetimestruct *upper
)
cdef int64_t convert_reso(
int64_t value,
NPY_DATETIMEUNIT from_reso,
NPY_DATETIMEUNIT to_reso,
bint round_ok,
) except? -1