From ef3183ca1269dbcaa1d50959a38084df4400f27d Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Sat, 21 Mar 2020 21:06:58 +0200 Subject: [PATCH 1/3] Added `const` where avaible --- pandas/_libs/tslibs/conversion.pyx | 12 ++++++++---- pandas/_libs/tslibs/offsets.pyx | 11 ++++++++--- pandas/_libs/tslibs/timedeltas.pyx | 2 +- pandas/_libs/tslibs/tzconversion.pyx | 5 +++-- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/pandas/_libs/tslibs/conversion.pyx b/pandas/_libs/tslibs/conversion.pyx index 57483783faf9f..10edf0bea54a7 100644 --- a/pandas/_libs/tslibs/conversion.pyx +++ b/pandas/_libs/tslibs/conversion.pyx @@ -595,8 +595,12 @@ cdef inline void localize_tso(_TSObject obj, tzinfo tz): obj.tzinfo = tz -cdef inline bint _infer_tsobject_fold(_TSObject obj, ndarray[int64_t] trans, - int64_t[:] deltas, int32_t pos): +cdef inline bint _infer_tsobject_fold( + _TSObject obj, + ndarray[int64_t] trans, + const int64_t[:] deltas, + int32_t pos, +): """ Infer _TSObject fold property from value by assuming 0 and then setting to 1 if necessary. @@ -738,7 +742,7 @@ def normalize_i8_timestamps(int64_t[:] stamps, object tz): @cython.wraparound(False) @cython.boundscheck(False) -cdef int64_t[:] _normalize_local(int64_t[:] stamps, tzinfo tz): +cdef int64_t[:] _normalize_local(const int64_t[:] stamps, tzinfo tz): """ Normalize each of the (nanosecond) timestamps in the given array by rounding down to the beginning of the day (i.e. midnight) for the @@ -818,7 +822,7 @@ cdef inline int64_t _normalized_stamp(npy_datetimestruct *dts) nogil: @cython.wraparound(False) @cython.boundscheck(False) -def is_date_array_normalized(int64_t[:] stamps, object tz=None): +def is_date_array_normalized(const int64_t[:] stamps, object tz=None): """ Check if all of the given (nanosecond) timestamps are normalized to midnight, i.e. hour == minute == second == 0. If the optional timezone diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index da59c635b5a18..b568218691a28 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -609,8 +609,13 @@ cdef inline int month_add_months(npy_datetimestruct dts, int months) nogil: @cython.wraparound(False) @cython.boundscheck(False) -def shift_quarters(int64_t[:] dtindex, int quarters, - int q1start_month, object day, int modby=3): +def shift_quarters( + const int64_t[:] dtindex, + int quarters, + int q1start_month, + object day, + int modby=3, +): """ Given an int64 array representing nanosecond timestamps, shift all elements by the specified number of quarters using DateOffset semantics. @@ -759,7 +764,7 @@ def shift_quarters(int64_t[:] dtindex, int quarters, @cython.wraparound(False) @cython.boundscheck(False) -def shift_months(int64_t[:] dtindex, int months, object day=None): +def shift_months(const int64_t[:] dtindex, int months, object day=None): """ Given an int64-based datetime index, shift all elements specified number of months using DateOffset semantics diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index 457f3eb0749c2..c31e8e3f7b4bb 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -101,7 +101,7 @@ _no_input = object() @cython.boundscheck(False) @cython.wraparound(False) -def ints_to_pytimedelta(int64_t[:] arr, box=False): +def ints_to_pytimedelta(const int64_t[:] arr, box=False): """ convert an i8 repr to an ndarray of timedelta or Timedelta (if box == True) diff --git a/pandas/_libs/tslibs/tzconversion.pyx b/pandas/_libs/tslibs/tzconversion.pyx index a9702f91107ec..d0022e66110fe 100644 --- a/pandas/_libs/tslibs/tzconversion.pyx +++ b/pandas/_libs/tslibs/tzconversion.pyx @@ -549,8 +549,9 @@ cdef int64_t _tz_convert_tzlocal_fromutc(int64_t val, tzinfo tz, bint *fold): @cython.boundscheck(False) @cython.wraparound(False) -cdef int64_t[:] _tz_convert_dst(int64_t[:] values, tzinfo tz, - bint to_utc=True): +cdef int64_t[:] _tz_convert_dst( + const int64_t[:] values, tzinfo tz, bint to_utc=True +): """ tz_convert for non-UTC non-tzlocal cases where we have to check DST transitions pointwise. From 328785c7ace3cd0f7fc7467fb82c6c0a1d5f7e64 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Sun, 22 Mar 2020 00:36:59 +0200 Subject: [PATCH 2/3] Trying to use memoryviews REF: https://github.com/pandas-dev/pandas/pull/32893/files#r396033598 --- pandas/_libs/tslibs/conversion.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/conversion.pyx b/pandas/_libs/tslibs/conversion.pyx index 10edf0bea54a7..a318bea14b52b 100644 --- a/pandas/_libs/tslibs/conversion.pyx +++ b/pandas/_libs/tslibs/conversion.pyx @@ -597,7 +597,7 @@ cdef inline void localize_tso(_TSObject obj, tzinfo tz): cdef inline bint _infer_tsobject_fold( _TSObject obj, - ndarray[int64_t] trans, + const int64_t[:] trans, const int64_t[:] deltas, int32_t pos, ): From 10ce0ca2c63536f3c4fdefdfab184b4a6d97f312 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Mon, 23 Mar 2020 11:57:11 +0200 Subject: [PATCH 3/3] Nitpick, added a trailing comma --- pandas/_libs/tslibs/tzconversion.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/tzconversion.pyx b/pandas/_libs/tslibs/tzconversion.pyx index d0022e66110fe..6915783ac3aaa 100644 --- a/pandas/_libs/tslibs/tzconversion.pyx +++ b/pandas/_libs/tslibs/tzconversion.pyx @@ -550,7 +550,7 @@ cdef int64_t _tz_convert_tzlocal_fromutc(int64_t val, tzinfo tz, bint *fold): @cython.boundscheck(False) @cython.wraparound(False) cdef int64_t[:] _tz_convert_dst( - const int64_t[:] values, tzinfo tz, bint to_utc=True + const int64_t[:] values, tzinfo tz, bint to_utc=True, ): """ tz_convert for non-UTC non-tzlocal cases where we have to check