pandas-dev/pandas · error · ValueError

Offset {offset} did not increment date

Error message

Offset {offset} did not increment date

What it means

Raised inside the date_range generator when applying offset._apply(cur) to the current date does not move it forward (next_date <= cur). A zero or negative step in a forward range would loop forever, so pandas aborts. ValueError naming the offending offset.

Source

Thrown at pandas/core/arrays/datetimes.py:3275

    start = cast("Timestamp", start)
    end = cast("Timestamp", end)

    cur = start
    if offset.n >= 0:
        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 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

  1. Ensure the offset strictly advances dates — check offset.n > 0 and that apply is monotonic.
  2. Use a built-in freq string ('D', 'h', 'W') for standard ranges.
  3. For custom DateOffset subclasses, verify apply returns a strictly later timestamp for every input.

Example fix

# before
pd.date_range('2020-01-01', '2020-01-10', freq=pd.DateOffset(days=0))
# after
pd.date_range('2020-01-01', '2020-01-10', freq='D')
Defensive patterns

Strategy: validation

Validate before calling

def make_range(start, end, offset):
    if getattr(offset, 'n', 1) <= 0:
        raise ValueError(f'offset {offset!r} must be strictly positive for forward range')
    return pd.date_range(start, end, freq=offset)

Prevention

When it happens

Trigger: pd.date_range(start, end, freq=offset) where the offset is zero (e.g. a DateOffset(n=0)) or its apply collapses to the same/earlier date for that input; custom DateOffset subclass whose apply is not strictly increasing.

Common situations: Parameterizing freq with a computed n that can be 0; custom BusinessHour/offset logic that fails near DST; offsets that subtract instead of add due to sign bugs.

Related errors


AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07). Data as JSON: /api/errors/6e09afef0cf8532f. Report an issue: GitHub.