Skip to content

Commit f3f675c

Browse files
authored
BUG: resolution in datetimelike add/sub timedeltalike scalar (#49015)
1 parent 712c2b1 commit f3f675c

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

pandas/core/arrays/datetimelike.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,8 @@ def _add_timedeltalike_scalar(self, other):
12751275

12761276
# PeriodArray overrides, so we only get here with DTA/TDA
12771277
self = cast("DatetimeArray | TimedeltaArray", self)
1278-
other = Timedelta(other)._as_unit(self._unit)
1278+
other = Timedelta(other)
1279+
self, other = self._ensure_matching_resos(other)
12791280
return self._add_timedeltalike(other)
12801281

12811282
def _add_timedelta_arraylike(self, other: TimedeltaArray):

pandas/tests/tseries/offsets/test_offsets.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from pandas._libs.tslibs import (
2121
NaT,
22+
Timedelta,
2223
Timestamp,
2324
conversion,
2425
timezones,
@@ -566,6 +567,12 @@ def test_add_dt64_ndarray_non_nano(self, offset_types, unit, request):
566567
expected = dti._data + off
567568
result = dta + off
568569

570+
exp_unit = unit
571+
if isinstance(off, Tick) and off._reso > dta._reso:
572+
# cast to higher reso like we would with Timedelta scalar
573+
exp_unit = Timedelta(off)._unit
574+
expected = expected._as_unit(exp_unit)
575+
569576
if len(w):
570577
# PerformanceWarning was issued bc _apply_array raised, so we
571578
# fell back to object dtype, for which the code path does
@@ -576,9 +583,7 @@ def test_add_dt64_ndarray_non_nano(self, offset_types, unit, request):
576583
)
577584
request.node.add_marker(mark)
578585

579-
tm.assert_numpy_array_equal(
580-
result._ndarray, expected._ndarray.astype(arr.dtype)
581-
)
586+
tm.assert_numpy_array_equal(result._ndarray, expected._ndarray)
582587

583588

584589
class TestDateOffset(Base):

0 commit comments

Comments
 (0)