@@ -955,35 +955,6 @@ cdef inline int month_to_quarter(int month) nogil:
955955# ----------------------------------------------------------------------
956956# Period logic
957957
958- @ cython.wraparound (False )
959- @ cython.boundscheck (False )
960- def dt64arr_to_periodarr (const int64_t[:] dtarr , int freq , tz = None ):
961- """
962- Convert array of datetime64 values (passed in as 'i8' dtype) to a set of
963- periods corresponding to desired frequency, per period convention.
964- """
965- cdef:
966- int64_t[:] out
967- Py_ssize_t i, l
968- npy_datetimestruct dts
969-
970- l = len (dtarr)
971-
972- out = np.empty(l, dtype = ' i8' )
973-
974- if tz is None :
975- with nogil:
976- for i in range (l):
977- if dtarr[i] == NPY_NAT:
978- out[i] = NPY_NAT
979- continue
980- dt64_to_dtstruct(dtarr[i], & dts)
981- out[i] = get_period_ordinal(& dts, freq)
982- else :
983- out = localize_dt64arr_to_period(dtarr, freq, tz)
984- return out.base # .base to access underlying np.ndarray
985-
986-
987958@ cython.wraparound (False )
988959@ cython.boundscheck (False )
989960def periodarr_to_dt64arr (const int64_t[:] periodarr , int freq ):
@@ -1473,8 +1444,7 @@ def extract_freq(ndarray[object] values):
14731444
14741445@ cython.wraparound (False )
14751446@ cython.boundscheck (False )
1476- cdef int64_t[:] localize_dt64arr_to_period(const int64_t[:] stamps,
1477- int freq, object tz):
1447+ def dt64arr_to_periodarr (const int64_t[:] stamps , int freq , object tz ):
14781448 cdef:
14791449 Py_ssize_t n = len (stamps)
14801450 int64_t[:] result = np.empty(n, dtype = np.int64)
@@ -1523,7 +1493,7 @@ cdef int64_t[:] localize_dt64arr_to_period(const int64_t[:] stamps,
15231493 dt64_to_dtstruct(stamps[i] + deltas[pos[i]], & dts)
15241494 result[i] = get_period_ordinal(& dts, freq)
15251495
1526- return result
1496+ return result.base # .base to get underlying ndarray
15271497
15281498
15291499DIFFERENT_FREQ = (" Input has different freq={other_freq} "
0 commit comments