Skip to content

Commit d60bea8

Browse files
simonjayhawkinsKevin D Smith
authored and
Kevin D Smith
committed
Partial Revert "ENH: infer freq in timedelta_range (pandas-dev#32377)" (pandas-dev#36595)
1 parent 915cbac commit d60bea8

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

doc/source/whatsnew/v1.1.3.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Fixed regressions
3131
~~~~~~~~~~~~~~~~~
3232
- Fixed regression in :meth:`DataFrame.agg`, :meth:`DataFrame.apply`, :meth:`Series.agg`, and :meth:`Series.apply` where internal suffix is exposed to the users when no relabelling is applied (:issue:`36189`)
3333
- Fixed regression in :class:`IntegerArray` unary plus and minus operations raising a ``TypeError`` (:issue:`36063`)
34+
- Fixed regression when adding a :meth:`timedelta_range` to a :class:``Timestamp`` raised an ``ValueError`` (:issue:`35897`)
3435
- Fixed regression in :meth:`Series.__getitem__` incorrectly raising when the input was a tuple (:issue:`35534`)
3536
- Fixed regression in :meth:`Series.__getitem__` incorrectly raising when the input was a frozenset (:issue:`35747`)
3637
- Fixed regression in :meth:`read_excel` with ``engine="odf"`` caused ``UnboundLocalError`` in some cases where cells had nested child nodes (:issue:`36122`, :issue:`35802`)
@@ -62,7 +63,7 @@ Bug fixes
6263

6364
Other
6465
~~~~~
65-
-
66+
- Reverted enhancement added in pandas-1.1.0 where :func:`timedelta_range` infers a frequency when passed ``start``, ``stop``, and ``periods`` (:issue:`32377`)
6667

6768
.. ---------------------------------------------------------------------------
6869

pandas/core/arrays/timedeltas.py

-4
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,6 @@ def _generate_range(cls, start, end, periods, freq, closed=None):
264264
index = generate_regular_range(start, end, periods, freq)
265265
else:
266266
index = np.linspace(start.value, end.value, periods).astype("i8")
267-
if len(index) >= 2:
268-
# Infer a frequency
269-
td = Timedelta(index[1] - index[0])
270-
freq = to_offset(td)
271267

272268
if not left_closed:
273269
index = index[1:]

pandas/core/indexes/timedeltas.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ def timedelta_range(
328328
329329
>>> pd.timedelta_range(start='1 day', end='5 days', periods=4)
330330
TimedeltaIndex(['1 days 00:00:00', '2 days 08:00:00', '3 days 16:00:00',
331-
'5 days 00:00:00'],
332-
dtype='timedelta64[ns]', freq='32H')
331+
'5 days 00:00:00'],
332+
dtype='timedelta64[ns]', freq=None)
333333
"""
334334
if freq is None and com.any_none(periods, start, end):
335335
freq = "D"

pandas/tests/arithmetic/test_timedelta64.py

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

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

pandas/tests/indexes/timedeltas/test_timedelta_range.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def test_linspace_behavior(self, periods, freq):
3838
result = timedelta_range(start="0 days", end="4 days", periods=periods)
3939
expected = timedelta_range(start="0 days", end="4 days", freq=freq)
4040
tm.assert_index_equal(result, expected)
41-
assert result.freq == freq
4241

4342
def test_errors(self):
4443
# not enough params
@@ -79,3 +78,8 @@ def test_timedelta_range_freq_divide_end(self, start, end, freq, expected_period
7978
assert Timedelta(start) == res[0]
8079
assert Timedelta(end) >= res[-1]
8180
assert len(res) == expected_periods
81+
82+
def test_timedelta_range_infer_freq(self):
83+
# https://github.com/pandas-dev/pandas/issues/35897
84+
result = timedelta_range("0s", "1s", periods=31)
85+
assert result.freq is None

0 commit comments

Comments
 (0)