Skip to content

BUG: Begin RecursiveLS dynamic prediction at a dynamic date - #11104

Merged
bashtage merged 6 commits into
statsmodels:mainfrom
bashtage:wip-recursivels-dynamic-date
Nov 24, 2026
Merged

bashtage merged 6 commits into
statsmodels:mainfrom
bashtage:wip-recursivels-dynamic-date

Conversation

@bashtage

Copy link
Copy Markdown
Member

Stacked on #10940, merge that first (its commits are the first ones here; this PR adds one commit). Both change the lines that convert dynamic in RecursiveLSResults.get_prediction.

BUG: Accept dynamic date keys that cover several dates

A dynamic date key that matches several dates of a DatetimeIndex, such
as "2001-04" for daily data, gives a slice of locations, which raised
"TypeError: unsupported operand type(s) for -=: 'slice' and 'int'" in
AutoReg.predict (and so ARDL.predict), MLEResults.get_prediction
(SARIMAX, ARIMA, UnobservedComponents, ...), STLForecastResults,
ETSResults and RecursiveLSResults.get_prediction. Dynamic prediction
now begins at the first date of the key, as MLEResults.simulate already
does for a multi-date anchor.

TST: Check a single-date dynamic key of RecursiveLS

Covers the branch of the new slice check where a date string matches a
single date, so that its location is used unchanged.

BUG: Begin RecursiveLS dynamic prediction at a dynamic date

RecursiveLSResults.get_prediction (and so predict) used the location of a
dynamic date string as an offset relative to start. With start=10,
dynamic="2001-04-01" began dynamic prediction on 2001-04-11, silently. The
shared docstring says that a date is not interpreted as an offset, and
MLEResults.get_prediction converts it to an offset by subtracting start. A
dynamic Timestamp or datetime raised "TypeError: Addition/subtraction of
integers and integer-arrays with Timestamp is no longer supported".

Changes

  • A dynamic date string, Timestamp or datetime is converted to its
    location and then to an offset relative to start, as in
    MLEResults.get_prediction, so dynamic prediction begins at that date.
    Results change when start is not the first observation.
  • The docstring notes the change in a versionchanged directive.

Not changed

  • An integer or bool dynamic, which is an offset relative to start.
  • A dynamic date when start is the first observation (the default).
  • The check that raises NotImplementedError for dynamic prediction in a
    model with constraints. As for an integer offset of 0, a dynamic date
    equal to start is not caught by it.

Tests

  • With start=10 or start="2000-01-11", a dynamic date string, month string,
    Timestamp or datetime gives the predictions from the coefficients
    estimated through the previous period up to the date, and from those
    estimated through the period before the date after it, and the same
    predictions and variances as the integer offset. All eight cases fail on
    main.

  • tests added / passed.

  • code/documentation is well formatted.

  • properly formatted commit message. See
    NumPy's guide.

AI Disclosure

Contributions must comply with the statsmodels AI Policy.

Tick exactly one of the following. If AI tools were used, replace the <...>
placeholders in the second option with the tool name(s) and how the tool's output was
used.

  • No AI tools were used to develop this pull request.
  • AI tools were used.
    Tool(s): Claude Code (Claude Opus 5.5).
    Used for: finding the bug in a coverage audit of the time series models, writing the fix and its tests, and checking them (tests failing on main, mutation check).
    I have personally read, understood, and can explain every line of this diff, and
    have verified the statistical/numerical correctness of the change.

🤖 Generated with Claude Code

A `dynamic` date key that matches several dates of a DatetimeIndex, such
as "2001-04" for daily data, gives a slice of locations, which raised
"TypeError: unsupported operand type(s) for -=: 'slice' and 'int'" in
`AutoReg.predict` (and so `ARDL.predict`), `MLEResults.get_prediction`
(SARIMAX, ARIMA, UnobservedComponents, ...), `STLForecastResults`,
`ETSResults` and `RecursiveLSResults.get_prediction`. Dynamic prediction
now begins at the first date of the key, as `MLEResults.simulate` already
does for a multi-date `anchor`.
Covers the branch of the new slice check where a date string matches a
single date, so that its location is used unchanged.
Since statsmodels#10975 merged, ETSModel.fit, fit_constrained and smooth warn when
param_index is not given (the default changes from "integer" to "names"
after statsmodels 0.17). The tests this PR adds called them without it,
so they leaked that FutureWarning. Pass param_index="integer", as the
existing tests do; results are unchanged.
RecursiveLSResults.get_prediction (and so predict) used the location of a
dynamic date string as an offset relative to start. With start=10,
dynamic="2001-04-01" began dynamic prediction on 2001-04-11, silently. The
shared docstring says that a date is not interpreted as an offset, and
MLEResults.get_prediction converts it to an offset by subtracting start. A
dynamic Timestamp or datetime raised "TypeError: Addition/subtraction of
integers and integer-arrays with Timestamp is no longer supported".

Changes
- A dynamic date string, Timestamp or datetime is converted to its
  location and then to an offset relative to start, as in
  MLEResults.get_prediction, so dynamic prediction begins at that date.
  Results change when start is not the first observation.
- The docstring notes the change in a versionchanged directive.

Not changed
- An integer or bool dynamic, which is an offset relative to start.
- A dynamic date when start is the first observation (the default).
- The check that raises NotImplementedError for dynamic prediction in a
  model with constraints. As for an integer offset of 0, a dynamic date
  equal to start is not caught by it.

Tests
- With start=10 or start="2000-01-11", a dynamic date string, month string,
  Timestamp or datetime gives the predictions from the coefficients
  estimated through the previous period up to the date, and from those
  estimated through the period before the date after it, and the same
  predictions and variances as the integer offset. All eight cases fail on
  main.
@bashtage
bashtage force-pushed the wip-recursivels-dynamic-date branch from 2462a6e to aff784e Compare November 24, 2026 16:17
@bashtage
bashtage marked this pull request as ready for review November 24, 2026 18:31
@bashtage
bashtage merged commit fe7b3a4 into statsmodels:main Nov 24, 2026
10 of 11 checks passed
@bashtage
bashtage deleted the wip-recursivels-dynamic-date branch November 24, 2026 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant