pandas-dev/pandas · error · ValueError
Offset {offset} did not decrement date
Error message
Offset {offset} did not decrement date What it means
Mirror of 295 for a descending range: applying offset._apply(cur) does not move the date backward (next_date >= cur), so the loop cannot terminate. ValueError naming the offset. Reached via date_range with a negative direction or a backwards iteration.
Source
Thrown at pandas/core/arrays/datetimes.py:3290
next_date = offset._apply(cur)
next_date = next_date.as_unit(unit)
if next_date <= cur:
raise ValueError(f"Offset {offset} did not increment date")
cur = next_date
else:
while cur >= end:
yield cur
if cur == end:
# GH#24252 avoid overflows by not performing the addition
# in offset.apply unless we have to
break
# faster than cur + offset
next_date = offset._apply(cur)
next_date = next_date.as_unit(unit)
if next_date >= cur:
raise ValueError(f"Offset {offset} did not decrement date")
cur = next_date
View on GitHub (pinned to 71959b8cb9)
Solutions
- Ensure the offset strictly decrements dates (offset.n < 0 or apply yields earlier timestamps).
- Use a negative freq string ('-1D') or reverse a forward range with [::-1].
- Validate custom DateOffset.apply is strictly monotonic in the expected direction.
Example fix
# before
pd.date_range('2020-01-10', '2020-01-01', freq=pd.DateOffset(days=0))
# after
pd.date_range('2020-01-10', '2020-01-01', freq='-1D') Defensive patterns
Strategy: validation
Validate before calling
def make_range_desc(start, end, offset):
if getattr(offset, 'n', 0) >= 0:
raise ValueError(f'offset {offset!r} must be strictly negative for backward range')
return pd.date_range(start, end, freq=offset) Prevention
- Use negative freq strings ('-1D') for descending ranges.
- Validate offset.n < 0 for backward ranges.
- Reverse a forward range with [::-1] instead of negative offsets when possible.
When it happens
Trigger: Generating a reverse date_range with an offset that is non-negative or zero; a custom offset whose apply does not strictly decrement; freq with n >= 0 used in a backward context.
Common situations: Sign error when building an offset for descending ranges; custom offset logic that adds instead of subtracts.
Related errors
- Offset {offset} did not increment date
- overflow in timedelta operation
- Cannot compare tz-naive and tz-aware datetime-like objects.
- Cannot compare tz-naive and tz-aware datetime-like objects
- Cannot convert tz-naive timestamps, use tz_localize to local
AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07).
Data as JSON: /api/errors/cf130195fc75d099.
Report an issue: GitHub.