Skip to content

Commit 7c5246c

Browse files
authored
CLN: de-duplicate paths in tslibs (#34400)
1 parent 7e1fab9 commit 7c5246c

File tree

3 files changed

+7
-45
lines changed

3 files changed

+7
-45
lines changed

pandas/_libs/tslibs/parsing.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ cpdef bint _does_string_look_like_datetime(str py_string):
376376
return True
377377

378378

379-
cdef inline object _parse_dateabbr_string(object date_string, object default,
379+
cdef inline object _parse_dateabbr_string(object date_string, datetime default,
380380
object freq):
381381
cdef:
382382
object ret

pandas/_libs/tslibs/period.pyx

+2-32
Original file line numberDiff line numberDiff line change
@@ -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)
989960
def 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

15291499
DIFFERENT_FREQ = ("Input has different freq={other_freq} "

pandas/_libs/tslibs/resolution.pyx

+4-12
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,19 @@ cdef:
2828

2929
# ----------------------------------------------------------------------
3030

31-
cpdef resolution(const int64_t[:] stamps, tz=None):
31+
def resolution(const int64_t[:] stamps, tz=None):
3232
cdef:
3333
Py_ssize_t i, n = len(stamps)
3434
npy_datetimestruct dts
3535
int reso = RESO_DAY, curr_reso
36-
37-
if tz is not None:
38-
tz = maybe_get_tz(tz)
39-
return _reso_local(stamps, tz)
40-
41-
42-
cdef _reso_local(const int64_t[:] stamps, object tz):
43-
cdef:
44-
Py_ssize_t i, n = len(stamps)
45-
int reso = RESO_DAY, curr_reso
4636
ndarray[int64_t] trans
4737
int64_t[:] deltas
4838
Py_ssize_t[:] pos
49-
npy_datetimestruct dts
5039
int64_t local_val, delta
5140

41+
if tz is not None:
42+
tz = maybe_get_tz(tz)
43+
5244
if is_utc(tz) or tz is None:
5345
for i in range(n):
5446
if stamps[i] == NPY_NAT:

0 commit comments

Comments
 (0)