Skip to content

REF: Cleanups, typing, memoryviews in tslibs #23368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Prev Previous commit
Next Next commit
optimizations
  • Loading branch information
jbrockmendel committed Oct 30, 2018
commit ae04c77e14cc39200dba73559a26a5afc4bcceca
10 changes: 10 additions & 0 deletions pandas/_libs/tslibs/conversion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ cdef inline int64_t get_datetime64_nanos(object val) except? -1:
return ival


@cython.boundscheck(False)
@cython.wraparound(False)
def ensure_datetime64ns(arr: ndarray, copy: bint = True):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no spaces on the args

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been trying to figure this out too. Are you sure about this? I've been following the usage here https://www.python.org/dev/peps/pep-3107/#syntax

"""
Ensure a np.datetime64 array has dtype specifically 'datetime64[ns]'
Expand Down Expand Up @@ -138,6 +140,8 @@ def ensure_timedelta64ns(arr: ndarray, copy: bint = True):
# TODO: check for overflows when going from a lower-resolution to nanos


@cython.boundscheck(False)
@cython.wraparound(False)
def datetime_to_datetime64(values: object[:]):
"""
Convert ndarray of datetime-like objects to int64 array representing
Expand Down Expand Up @@ -611,6 +615,8 @@ cpdef inline datetime localize_pydatetime(datetime dt, object tz):
# ----------------------------------------------------------------------
# Timezone Conversion

@cython.boundscheck(False)
@cython.wraparound(False)
cdef inline int64_t[:] _tz_convert_dst(int64_t[:] values, tzinfo tz,
bint to_utc=True):
"""
Expand Down Expand Up @@ -757,6 +763,8 @@ cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2):
return _tz_convert_dst(arr, tz2, to_utc=False)[0]


@cython.boundscheck(False)
@cython.wraparound(False)
cdef inline int64_t[:] _tz_convert_one_way(int64_t[:] vals, object tz,
bint to_utc):
"""
Expand Down Expand Up @@ -1215,6 +1223,8 @@ cdef inline int64_t _normalized_stamp(npy_datetimestruct *dts) nogil:
return dtstruct_to_dt64(dts)


@cython.boundscheck(False)
@cython.wraparound(False)
def is_date_array_normalized(int64_t[:] stamps, object tz=None):
"""
Check if all of the given (nanosecond) timestamps are normalized to
Expand Down
3 changes: 3 additions & 0 deletions pandas/_libs/tslibs/fields.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def get_time_micros(ndarray[int64_t] dtindex):
return micros


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


@cython.wraparound(False)
@cython.boundscheck(False)
def get_start_end_field(int64_t[:] dtindex, object field,
object freqstr=None, int month_kw=12):
"""
Expand Down
5 changes: 5 additions & 0 deletions pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import warnings
import sys
cdef bint PY3 = (sys.version_info[0] >= 3)

import cython
from cython import Py_ssize_t

from cpython cimport Py_NE, Py_EQ, PyObject_RichCompare
Expand Down Expand Up @@ -82,6 +83,8 @@ _no_input = object()
# ----------------------------------------------------------------------
# API

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


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