diff --git a/pandas/_libs/index.pyx b/pandas/_libs/index.pyx index 1d0eb256ca051..6aa93d9780913 100644 --- a/pandas/_libs/index.pyx +++ b/pandas/_libs/index.pyx @@ -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: @@ -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) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index e268a5d74908e..68577113702eb 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -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 = { @@ -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"): @@ -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 @@ -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: diff --git a/pandas/_libs/tslibs/timedeltas.pxd b/pandas/_libs/tslibs/timedeltas.pxd index 7c597cb4b102b..feec08840cb98 100644 --- a/pandas/_libs/tslibs/timedeltas.pxd +++ b/pandas/_libs/tslibs/timedeltas.pxd @@ -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) diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index fe2e927443021..2beb3470318b5 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -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: @@ -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 @@ -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 diff --git a/pandas/_libs/tslibs/timestamps.pxd b/pandas/_libs/tslibs/timestamps.pxd index 0ecb26822cf50..09aa682fd57a5 100644 --- a/pandas/_libs/tslibs/timestamps.pxd +++ b/pandas/_libs/tslibs/timestamps.pxd @@ -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=*) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index c166edf35946c..49660ef4c181b 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -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 @@ -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 @@ -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 @@ -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."