diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index d37c287be4cfd..f1ebe9dd6348f 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -70,6 +70,7 @@ from pandas._libs.tslibs.np_datetime cimport ( from .dtypes cimport PeriodDtypeCode from .timedeltas cimport ( + _Timedelta, delta_to_nanoseconds, is_any_td_scalar, ) @@ -1140,7 +1141,9 @@ cdef class RelativeDeltaOffset(BaseOffset): weeks = kwds.get("weeks", 0) * self.n if weeks: - dt64other = dt64other + Timedelta(days=7 * weeks) + delta = Timedelta(days=7 * weeks) + td = (<_Timedelta>delta)._as_reso(reso) + dt64other = dt64other + td timedelta_kwds = { k: v @@ -1149,13 +1152,14 @@ cdef class RelativeDeltaOffset(BaseOffset): } if timedelta_kwds: delta = Timedelta(**timedelta_kwds) - dt64other = dt64other + (self.n * delta) - # FIXME: fails to preserve non-nano + td = (<_Timedelta>delta)._as_reso(reso) + dt64other = dt64other + (self.n * td) return dt64other elif not self._use_relativedelta and hasattr(self, "_offset"): # timedelta - # FIXME: fails to preserve non-nano - return dt64other + Timedelta(self._offset * self.n) + delta = Timedelta(self._offset * self.n) + td = (<_Timedelta>delta)._as_reso(reso) + return dt64other + td else: # relativedelta with other keywords kwd = set(kwds) - relativedelta_fast diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index cf5cbe6e2af66..49661fe1ec8ce 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -556,10 +556,6 @@ def test_add_dt64_ndarray_non_nano(self, offset_types, unit, request): # check that the result with non-nano matches nano off = self._get_offset(offset_types) - if type(off) is DateOffset: - mark = pytest.mark.xfail(reason="non-nano not implemented") - request.node.add_marker(mark) - dti = date_range("2016-01-01", periods=35, freq="D") arr = dti._data._ndarray.astype(f"M8[{unit}]")