Skip to content

Commit dee2c55

Browse files
authored
Fix regression when adding timeldeta_range to timestamp (#36582)
1 parent f957330 commit dee2c55

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

doc/source/whatsnew/v1.1.3.rst

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Fixed regressions
3838
- Fixed regression in :meth:`DataFrame.apply` with ``raw=True`` and user-function returning string (:issue:`35940`)
3939
- Fixed regression when setting empty :class:`DataFrame` column to a :class:`Series` in preserving name of index in frame (:issue:`36527`)
4040
- Fixed regression in :class:`Period` incorrect value for ordinal over the maximum timestamp (:issue:`36430`)
41+
- Fixed regression when adding a :meth:`timedelta_range` to a :class:``Timestamp`` raised an ``ValueError`` (:issue:`35897`)
4142

4243
.. ---------------------------------------------------------------------------
4344

pandas/core/arrays/timedeltas.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ def _add_datetimelike_scalar(self, other):
450450
result = checked_add_with_arr(i8, other.value, arr_mask=self._isnan)
451451
result = self._maybe_mask_results(result)
452452
dtype = DatetimeTZDtype(tz=other.tz) if other.tz else DT64NS_DTYPE
453-
return DatetimeArray(result, dtype=dtype, freq=self.freq)
453+
return DatetimeArray._simple_new(result, dtype=dtype, freq=self.freq)
454454

455455
def _addsub_object_array(self, other, op):
456456
# Add or subtract Array-like of objects

pandas/tests/arithmetic/test_timedelta64.py

+17
Original file line numberDiff line numberDiff line change
@@ -2136,3 +2136,20 @@ def test_td64arr_pow_invalid(self, scalar_td, box_with_array):
21362136

21372137
with pytest.raises(TypeError, match=pattern):
21382138
td1 ** scalar_td
2139+
2140+
2141+
def test_add_timestamp_to_timedelta():
2142+
# GH: 35897
2143+
timestamp = pd.Timestamp.now()
2144+
result = timestamp + pd.timedelta_range("0s", "1s", periods=31)
2145+
expected = pd.DatetimeIndex(
2146+
[
2147+
timestamp
2148+
+ (
2149+
pd.to_timedelta("0.033333333s") * i
2150+
+ pd.to_timedelta("0.000000001s") * divmod(i, 3)[0]
2151+
)
2152+
for i in range(31)
2153+
]
2154+
)
2155+
tm.assert_index_equal(result, expected)

0 commit comments

Comments
 (0)