Skip to content

REF: _as_reso->_as_creso #49098

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
Oct 14, 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
8 changes: 4 additions & 4 deletions pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ cdef class DatetimeEngine(Int64Engine):
return scalar.value
else:
# Note: caller is responsible for catching potential ValueError
# from _as_reso
return (<_Timestamp>scalar)._as_reso(self.reso, round_ok=False).value
# from _as_creso
return (<_Timestamp>scalar)._as_creso(self.reso, round_ok=False).value
raise TypeError(scalar)

def __contains__(self, val: object) -> bool:
Expand Down Expand Up @@ -574,8 +574,8 @@ cdef class TimedeltaEngine(DatetimeEngine):
return scalar.value
else:
# Note: caller is responsible for catching potential ValueError
# from _as_reso
return (<_Timedelta>scalar)._as_reso(self.reso, round_ok=False).value
# from _as_creso
return (<_Timedelta>scalar)._as_creso(self.reso, round_ok=False).value
raise TypeError(scalar)


Expand Down
8 changes: 4 additions & 4 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@ cdef class RelativeDeltaOffset(BaseOffset):
weeks = kwds.get("weeks", 0) * self.n
if weeks:
delta = Timedelta(days=7 * weeks)
td = (<_Timedelta>delta)._as_reso(reso)
td = (<_Timedelta>delta)._as_creso(reso)
dt64other = dt64other + td

timedelta_kwds = {
Expand All @@ -1335,7 +1335,7 @@ cdef class RelativeDeltaOffset(BaseOffset):
}
if timedelta_kwds:
delta = Timedelta(**timedelta_kwds)
td = (<_Timedelta>delta)._as_reso(reso)
td = (<_Timedelta>delta)._as_creso(reso)
dt64other = dt64other + (self.n * td)
return dt64other
elif not self._use_relativedelta and hasattr(self, "_offset"):
Expand All @@ -1346,7 +1346,7 @@ cdef class RelativeDeltaOffset(BaseOffset):
delta = Timedelta((self._offset + rem_nano) * self.n)
else:
delta = Timedelta(self._offset * self.n)
td = (<_Timedelta>delta)._as_reso(reso)
td = (<_Timedelta>delta)._as_creso(reso)
return dt64other + td
else:
# relativedelta with other keywords
Expand Down Expand Up @@ -3394,7 +3394,7 @@ cdef class FY5253Quarter(FY5253Mixin):
for qlen in qtr_lens:
if qlen * 7 <= tdelta.days:
num_qtrs += 1
tdelta -= (<_Timedelta>Timedelta(days=qlen * 7))._as_reso(norm._reso)
tdelta -= (<_Timedelta>Timedelta(days=qlen * 7))._as_creso(norm._reso)
else:
break
else:
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/timedeltas.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ cdef class _Timedelta(timedelta):
cdef bint _has_ns(self)
cdef _ensure_components(_Timedelta self)
cdef inline bint _compare_mismatched_resos(self, _Timedelta other, op)
cdef _Timedelta _as_reso(self, NPY_DATETIMEUNIT reso, bint round_ok=*)
cdef _Timedelta _as_creso(self, NPY_DATETIMEUNIT reso, bint round_ok=*)
cpdef _maybe_cast_to_matching_resos(self, _Timedelta other)
12 changes: 6 additions & 6 deletions pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -793,9 +793,9 @@ def _binary_op_method_timedeltalike(op, name):
# Matching numpy, we cast to the higher resolution. Unlike numpy,
# we raise instead of silently overflowing during this casting.
if self._reso < other._reso:
self = (<_Timedelta>self)._as_reso(other._reso, round_ok=True)
self = (<_Timedelta>self)._as_creso(other._reso, round_ok=True)
elif self._reso > other._reso:
other = (<_Timedelta>other)._as_reso(self._reso, round_ok=True)
other = (<_Timedelta>other)._as_creso(self._reso, round_ok=True)

res = op(self.value, other.value)
if res == NPY_NAT:
Expand Down Expand Up @@ -1541,10 +1541,10 @@ cdef class _Timedelta(timedelta):
def _as_unit(self, str unit, bint round_ok=True):
dtype = np.dtype(f"m8[{unit}]")
reso = get_unit_from_dtype(dtype)
return self._as_reso(reso, round_ok=round_ok)
return self._as_creso(reso, round_ok=round_ok)

@cython.cdivision(False)
cdef _Timedelta _as_reso(self, NPY_DATETIMEUNIT reso, bint round_ok=True):
cdef _Timedelta _as_creso(self, NPY_DATETIMEUNIT reso, bint round_ok=True):
cdef:
int64_t value

Expand All @@ -1566,9 +1566,9 @@ cdef class _Timedelta(timedelta):
If _resos do not match, cast to the higher resolution, raising on overflow.
"""
if self._reso > other._reso:
other = other._as_reso(self._reso)
other = other._as_creso(self._reso)
elif self._reso < other._reso:
self = self._as_reso(other._reso)
self = self._as_creso(other._reso)
return self, other


Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/timestamps.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ cdef class _Timestamp(ABCTimestamp):
cpdef void _set_freq(self, freq)
cdef _warn_on_field_deprecation(_Timestamp self, freq, str field)
cdef bint _compare_mismatched_resos(_Timestamp self, _Timestamp other, int op)
cdef _Timestamp _as_reso(_Timestamp self, NPY_DATETIMEUNIT reso, bint round_ok=*)
cdef _Timestamp _as_creso(_Timestamp self, NPY_DATETIMEUNIT reso, bint round_ok=*)
12 changes: 6 additions & 6 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,9 @@ cdef class _Timestamp(ABCTimestamp):
# Matching numpy, we cast to the higher resolution. Unlike numpy,
# we raise instead of silently overflowing during this casting.
if self._reso < other._reso:
self = (<_Timestamp>self)._as_reso(other._reso, round_ok=True)
self = (<_Timestamp>self)._as_creso(other._reso, round_ok=True)
elif self._reso > other._reso:
other = (<_Timedelta>other)._as_reso(self._reso, round_ok=True)
other = (<_Timedelta>other)._as_creso(self._reso, round_ok=True)

nanos = other.value

Expand Down Expand Up @@ -525,9 +525,9 @@ cdef class _Timestamp(ABCTimestamp):
# Matching numpy, we cast to the higher resolution. Unlike numpy,
# we raise instead of silently overflowing during this casting.
if self._reso < other._reso:
self = (<_Timestamp>self)._as_reso(other._reso, round_ok=False)
self = (<_Timestamp>self)._as_creso(other._reso, round_ok=False)
elif self._reso > other._reso:
other = (<_Timestamp>other)._as_reso(self._reso, round_ok=False)
other = (<_Timestamp>other)._as_creso(self._reso, round_ok=False)

# scalar Timestamp/datetime - Timestamp/datetime -> yields a
# Timedelta
Expand Down Expand Up @@ -1062,7 +1062,7 @@ cdef class _Timestamp(ABCTimestamp):
# Conversion Methods

@cython.cdivision(False)
cdef _Timestamp _as_reso(self, NPY_DATETIMEUNIT reso, bint round_ok=True):
cdef _Timestamp _as_creso(self, NPY_DATETIMEUNIT reso, bint round_ok=True):
cdef:
int64_t value

Expand All @@ -1076,7 +1076,7 @@ cdef class _Timestamp(ABCTimestamp):
dtype = np.dtype(f"M8[{unit}]")
reso = get_unit_from_dtype(dtype)
try:
return self._as_reso(reso, round_ok=round_ok)
return self._as_creso(reso, round_ok=round_ok)
except OverflowError as err:
raise OutOfBoundsDatetime(
f"Cannot cast {self} to unit='{unit}' without overflow."
Expand Down