{"record":{"id":"6e09afef0cf8532f","repo":"pandas-dev/pandas","slug":"offset-offset-did-not-increment-date","errorCode":null,"errorMessage":"Offset {offset} did not increment date","messagePattern":"Offset (.+?) did not increment date","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/datetimes.py","lineNumber":3275,"sourceCode":"\n    start = cast(\"Timestamp\", start)\n    end = cast(\"Timestamp\", end)\n\n    cur = start\n    if offset.n >= 0:\n        while cur <= end:\n            yield cur\n\n            if cur == end:\n                # GH#24252 avoid overflows by not performing the addition\n                # in offset.apply unless we have to\n                break\n\n            # faster than cur + offset\n            next_date = offset._apply(cur)\n            next_date = next_date.as_unit(unit)\n            if next_date <= cur:\n                raise ValueError(f\"Offset {offset} did not increment date\")\n            cur = next_date\n    else:\n        while cur >= end:\n            yield cur\n\n            if cur == end:\n                # GH#24252 avoid overflows by not performing the addition\n                # in offset.apply unless we have to\n                break\n\n            # faster than cur + offset\n            next_date = offset._apply(cur)\n            next_date = next_date.as_unit(unit)\n            if next_date >= cur:\n                raise ValueError(f\"Offset {offset} did not decrement date\")\n            cur = next_date\n","sourceCodeStart":3257,"sourceCodeEnd":3292,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/datetimes.py#L3257-L3292","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the offset strictly advances dates — check offset.n > 0 and that apply is monotonic.","Use a built-in freq string ('D', 'h', 'W') for standard ranges.","For custom DateOffset subclasses, verify apply returns a strictly later timestamp for every input."],"exampleFix":"# before\npd.date_range('2020-01-01', '2020-01-10', freq=pd.DateOffset(days=0))\n# after\npd.date_range('2020-01-01', '2020-01-10', freq='D')","handlingStrategy":"validation","validationCode":"def make_range(start, end, offset):\n    if getattr(offset, 'n', 1) <= 0:\n        raise ValueError(f'offset {offset!r} must be strictly positive for forward range')\n    return pd.date_range(start, end, freq=offset)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate offset.n > 0 for forward ranges.","Prefer standard freq strings.","Test custom DateOffset.apply for strict monotonic increase."],"tags":["datetime","date-range","offset","pandas"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}