Skip to content

REF: remove dtstruct_to_dt64 #47492

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 1 commit into from
Jun 24, 2022
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
7 changes: 3 additions & 4 deletions pandas/_libs/tslibs/conversion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ from pandas._libs.tslibs.np_datetime cimport (
NPY_FR_ns,
astype_overflowsafe,
check_dts_bounds,
dt64_to_dtstruct,
dtstruct_to_dt64,
get_datetime64_unit,
get_datetime64_value,
Expand Down Expand Up @@ -248,7 +247,7 @@ cdef _TSObject convert_to_tsobject(object ts, tzinfo tz, str unit,
elif is_datetime64_object(ts):
obj.value = get_datetime64_nanos(ts)
if obj.value != NPY_NAT:
dt64_to_dtstruct(obj.value, &obj.dts)
pandas_datetime_to_datetimestruct(obj.value, NPY_FR_ns, &obj.dts)
elif is_integer_object(ts):
try:
ts = <int64_t>ts
Expand All @@ -266,7 +265,7 @@ cdef _TSObject convert_to_tsobject(object ts, tzinfo tz, str unit,

ts = ts * cast_from_unit(None, unit)
obj.value = ts
dt64_to_dtstruct(ts, &obj.dts)
pandas_datetime_to_datetimestruct(ts, NPY_FR_ns, &obj.dts)
elif is_float_object(ts):
if ts != ts or ts == NPY_NAT:
obj.value = NPY_NAT
Expand All @@ -289,7 +288,7 @@ cdef _TSObject convert_to_tsobject(object ts, tzinfo tz, str unit,

ts = cast_from_unit(ts, unit)
obj.value = ts
dt64_to_dtstruct(ts, &obj.dts)
pandas_datetime_to_datetimestruct(ts, NPY_FR_ns, &obj.dts)
elif PyDateTime_Check(ts):
return convert_datetime_to_tsobject(ts, tz, nanos)
elif PyDate_Check(ts):
Expand Down
1 change: 0 additions & 1 deletion pandas/_libs/tslibs/np_datetime.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ cdef bint cmp_scalar(int64_t lhs, int64_t rhs, int op) except -1
cdef check_dts_bounds(npy_datetimestruct *dts, NPY_DATETIMEUNIT unit=?)

cdef int64_t dtstruct_to_dt64(npy_datetimestruct* dts) nogil
cdef void dt64_to_dtstruct(int64_t dt64, npy_datetimestruct* out) nogil

cdef int64_t pydatetime_to_dt64(datetime val, npy_datetimestruct *dts)
cdef void pydatetime_to_dtstruct(datetime dt, npy_datetimestruct *dts)
Expand Down
8 changes: 0 additions & 8 deletions pandas/_libs/tslibs/np_datetime.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,6 @@ cdef inline int64_t dtstruct_to_dt64(npy_datetimestruct* dts) nogil:
return npy_datetimestruct_to_datetime(NPY_FR_ns, dts)


cdef inline void dt64_to_dtstruct(int64_t dt64,
npy_datetimestruct* out) nogil:
"""Convenience function to call pandas_datetime_to_datetimestruct
with the by-far-most-common frequency NPY_FR_ns"""
pandas_datetime_to_datetimestruct(dt64, NPY_FR_ns, out)
return


# just exposed for testing at the moment
def py_td64_to_tdstruct(int64_t td64, NPY_DATETIMEUNIT unit):
cdef:
Expand Down
6 changes: 2 additions & 4 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ from pandas._libs.tslibs.np_datetime cimport (
NPY_FR_us,
astype_overflowsafe,
check_dts_bounds,
dt64_to_dtstruct,
dtstruct_to_dt64,
get_timedelta64_value,
npy_datetimestruct,
npy_datetimestruct_to_datetime,
Expand Down Expand Up @@ -813,7 +811,7 @@ cdef void get_date_info(int64_t ordinal, int freq, npy_datetimestruct *dts) nogi

pandas_datetime_to_datetimestruct(unix_date, NPY_FR_D, dts)

dt64_to_dtstruct(nanos, &dts2)
pandas_datetime_to_datetimestruct(nanos, NPY_DATETIMEUNIT.NPY_FR_ns, &dts2)
dts.hour = dts2.hour
dts.min = dts2.min
dts.sec = dts2.sec
Expand Down Expand Up @@ -1149,7 +1147,7 @@ cdef int64_t period_ordinal_to_dt64(int64_t ordinal, int freq) except? -1:
get_date_info(ordinal, freq, &dts)

check_dts_bounds(&dts)
return dtstruct_to_dt64(&dts)
return npy_datetimestruct_to_datetime(NPY_DATETIMEUNIT.NPY_FR_ns, &dts)


cdef str period_format(int64_t value, int freq, object fmt=None):
Expand Down
1 change: 0 additions & 1 deletion pandas/_libs/tslibs/vectorized.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ from .nattype cimport (
from .np_datetime cimport (
NPY_DATETIMEUNIT,
NPY_FR_ns,
dt64_to_dtstruct,
npy_datetimestruct,
pandas_datetime_to_datetimestruct,
)
Expand Down