Skip to content

CLN: de-duplicate paths in tslibs #34400

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

Merged
merged 7 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/parsing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ cpdef bint _does_string_look_like_datetime(str py_string):
return True


cdef inline object _parse_dateabbr_string(object date_string, object default,
cdef inline object _parse_dateabbr_string(object date_string, datetime default,
object freq):
cdef:
object ret
Expand Down
34 changes: 2 additions & 32 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -955,35 +955,6 @@ cdef inline int month_to_quarter(int month) nogil:
# ----------------------------------------------------------------------
# Period logic

@cython.wraparound(False)
@cython.boundscheck(False)
def dt64arr_to_periodarr(const int64_t[:] dtarr, int freq, tz=None):
"""
Convert array of datetime64 values (passed in as 'i8' dtype) to a set of
periods corresponding to desired frequency, per period convention.
"""
cdef:
int64_t[:] out
Py_ssize_t i, l
Copy link
Contributor

Choose a reason for hiding this comment

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

do we even need this routine any longer? (e.g. just call localize_dt64arr_to_period in the caller)

Copy link
Member Author

Choose a reason for hiding this comment

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

sure

npy_datetimestruct dts

l = len(dtarr)

out = np.empty(l, dtype='i8')

if tz is None:
with nogil:
for i in range(l):
if dtarr[i] == NPY_NAT:
out[i] = NPY_NAT
continue
dt64_to_dtstruct(dtarr[i], &dts)
out[i] = get_period_ordinal(&dts, freq)
else:
out = localize_dt64arr_to_period(dtarr, freq, tz)
return out.base # .base to access underlying np.ndarray


@cython.wraparound(False)
@cython.boundscheck(False)
def periodarr_to_dt64arr(const int64_t[:] periodarr, int freq):
Expand Down Expand Up @@ -1471,8 +1442,7 @@ def extract_freq(ndarray[object] values):

@cython.wraparound(False)
@cython.boundscheck(False)
cdef int64_t[:] localize_dt64arr_to_period(const int64_t[:] stamps,
int freq, object tz):
def dt64arr_to_periodarr(const int64_t[:] stamps, int freq, object tz):
cdef:
Py_ssize_t n = len(stamps)
int64_t[:] result = np.empty(n, dtype=np.int64)
Expand Down Expand Up @@ -1521,7 +1491,7 @@ cdef int64_t[:] localize_dt64arr_to_period(const int64_t[:] stamps,
dt64_to_dtstruct(stamps[i] + deltas[pos[i]], &dts)
result[i] = get_period_ordinal(&dts, freq)

return result
return result.base # .base to get underlying ndarray


DIFFERENT_FREQ = ("Input has different freq={other_freq} "
Expand Down
16 changes: 4 additions & 12 deletions pandas/_libs/tslibs/resolution.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,19 @@ cdef:

# ----------------------------------------------------------------------

cpdef resolution(const int64_t[:] stamps, tz=None):
def resolution(const int64_t[:] stamps, tz=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

not called in cython anylonger?

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure if it ever was

cdef:
Py_ssize_t i, n = len(stamps)
npy_datetimestruct dts
int reso = RESO_DAY, curr_reso

if tz is not None:
tz = maybe_get_tz(tz)
return _reso_local(stamps, tz)


cdef _reso_local(const int64_t[:] stamps, object tz):
cdef:
Py_ssize_t i, n = len(stamps)
int reso = RESO_DAY, curr_reso
ndarray[int64_t] trans
int64_t[:] deltas
Py_ssize_t[:] pos
npy_datetimestruct dts
int64_t local_val, delta

if tz is not None:
tz = maybe_get_tz(tz)

if is_utc(tz) or tz is None:
for i in range(n):
if stamps[i] == NPY_NAT:
Expand Down