Skip to content

Commit e087b94

Browse files
committed
optimizations
1 parent b6ec3e5 commit e087b94

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

pandas/_libs/tslibs/conversion.pyx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ cdef inline int64_t get_datetime64_nanos(object val) except? -1:
7474
return ival
7575

7676

77+
@cython.boundscheck(False)
78+
@cython.wraparound(False)
7779
def ensure_datetime64ns(arr: ndarray, copy: bint = True):
7880
"""
7981
Ensure a np.datetime64 array has dtype specifically 'datetime64[ns]'
@@ -138,6 +140,8 @@ def ensure_timedelta64ns(arr: ndarray, copy: bint = True):
138140
# TODO: check for overflows when going from a lower-resolution to nanos
139141

140142

143+
@cython.boundscheck(False)
144+
@cython.wraparound(False)
141145
def datetime_to_datetime64(values: object[:]):
142146
"""
143147
Convert ndarray of datetime-like objects to int64 array representing
@@ -611,6 +615,8 @@ cpdef inline datetime localize_pydatetime(datetime dt, object tz):
611615
# ----------------------------------------------------------------------
612616
# Timezone Conversion
613617

618+
@cython.boundscheck(False)
619+
@cython.wraparound(False)
614620
cdef inline int64_t[:] _tz_convert_dst(int64_t[:] values, tzinfo tz,
615621
bint to_utc=True):
616622
"""
@@ -757,6 +763,8 @@ cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2):
757763
return _tz_convert_dst(arr, tz2, to_utc=False)[0]
758764

759765

766+
@cython.boundscheck(False)
767+
@cython.wraparound(False)
760768
cdef inline int64_t[:] _tz_convert_one_way(int64_t[:] vals, object tz,
761769
bint to_utc):
762770
"""
@@ -1215,6 +1223,8 @@ cdef inline int64_t _normalized_stamp(npy_datetimestruct *dts) nogil:
12151223
return dtstruct_to_dt64(dts)
12161224

12171225

1226+
@cython.boundscheck(False)
1227+
@cython.wraparound(False)
12181228
def is_date_array_normalized(int64_t[:] stamps, object tz=None):
12191229
"""
12201230
Check if all of the given (nanosecond) timestamps are normalized to

pandas/_libs/tslibs/fields.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def get_time_micros(ndarray[int64_t] dtindex):
4040
return micros
4141

4242

43+
@cython.wraparound(False)
44+
@cython.boundscheck(False)
4345
def build_field_sarray(int64_t[:] dtindex):
4446
"""
4547
Datetime as int64 representation to a structured array of fields
@@ -134,6 +136,7 @@ def get_date_name_field(int64_t[:] dtindex, object field, object locale=None):
134136

135137

136138
@cython.wraparound(False)
139+
@cython.boundscheck(False)
137140
def get_start_end_field(int64_t[:] dtindex, object field,
138141
object freqstr=None, int month_kw=12):
139142
"""

pandas/_libs/tslibs/timedeltas.pyx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import warnings
66
import sys
77
cdef bint PY3 = (sys.version_info[0] >= 3)
88

9+
import cython
910
from cython import Py_ssize_t
1011

1112
from cpython cimport Py_NE, Py_EQ, PyObject_RichCompare
@@ -82,6 +83,8 @@ _no_input = object()
8283
# ----------------------------------------------------------------------
8384
# API
8485

86+
@cython.boundscheck(False)
87+
@cython.wraparound(False)
8588
def ints_to_pytimedelta(int64_t[:] arr, bint box=False):
8689
"""
8790
convert an i8 repr to an ndarray of timedelta or Timedelta (if box ==
@@ -198,6 +201,8 @@ cpdef convert_to_timedelta64(object ts, object unit):
198201
return ts.astype('timedelta64[ns]')
199202

200203

204+
@cython.boundscheck(False)
205+
@cython.wraparound(False)
201206
def array_to_timedelta64(object[:] values, unit='ns', errors='raise'):
202207
"""
203208
Convert an ndarray to an array of timedeltas. If errors == 'coerce',

0 commit comments

Comments
 (0)