{"record":{"id":"cf130195fc75d099","repo":"pandas-dev/pandas","slug":"offset-offset-did-not-decrement-date","errorCode":null,"errorMessage":"Offset {offset} did not decrement date","messagePattern":"Offset (.+?) did not decrement date","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/datetimes.py","lineNumber":3290,"sourceCode":"            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":3272,"sourceCodeEnd":3292,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/datetimes.py#L3272-L3292","documentation":"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.","triggerScenarios":"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.","commonSituations":"Sign error when building an offset for descending ranges; custom offset logic that adds instead of subtracts.","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."],"exampleFix":"# before\npd.date_range('2020-01-10', '2020-01-01', freq=pd.DateOffset(days=0))\n# after\npd.date_range('2020-01-10', '2020-01-01', freq='-1D')","handlingStrategy":"validation","validationCode":"def make_range_desc(start, end, offset):\n    if getattr(offset, 'n', 0) >= 0:\n        raise ValueError(f'offset {offset!r} must be strictly negative for backward range')\n    return pd.date_range(start, end, freq=offset)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["datetime","date-range","offset","pandas"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}