Skip to content

BUG: Accept dynamic date keys that cover several dates - #10940

Merged
bashtage merged 5 commits into
statsmodels:mainfrom
bashtage:wip-tsa-dynamic-date-slice
Nov 24, 2026
Merged

bashtage merged 5 commits into
statsmodels:mainfrom
bashtage:wip-tsa-dynamic-date-slice

Conversation

@bashtage

Copy link
Copy Markdown
Member

A dynamic date key that matches several dates of a DatetimeIndex, such as
"2001-04" for daily data, gives a slice of locations. That raised
"TypeError: unsupported operand type(s) for -=: 'slice' and 'int'" in
AutoReg.predict (and ARDL.predict), MLEResults.get_prediction
(SARIMAX, ARIMA, UnobservedComponents, ...),
STLForecastResults.get_prediction, ETSResults.predict and
get_prediction, and RecursiveLSResults.get_prediction. Once #10921 is
merged, dynamic="2001Q2" on daily data reaches this too.

Changes

  • At each site, dynamic prediction begins at the first date of the key, as
    MLEResults.simulate already does for a multi-date anchor.

Not changed

  • Keys that match one date, integer offsets, and True/False.
  • VARMAXResults.simulate's anchor has the same problem; it is left for
    a separate PR.

Tests

  • One test per site: a key covering April 2001 equals the integer offset
    of 2001-04-01 (location computed by hand and checked against
    pd.date_range). All 6 fail on main. With BUG: Select the whole quarter for "YYYYQn" keys on date indexes #10921 merged,
    dynamic="2001Q2" on daily data equals the same offset at every site.

  • 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 contract audit, 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

@bashtage

bashtage commented Nov 23, 2026 •

Copy link
Copy Markdown
Member Author

Merge order. These open PRs build on this one (their branches contain its commits), so please merge this PR first:

Indented PRs build on the PR above them, so merge them after it.

Once this PR is merged, their diffs shrink to their own changes. Each of them also says "Stacked on #..." at the top of its description.

Merge-order note 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.
@bashtage
bashtage force-pushed the wip-tsa-dynamic-date-slice branch from af08ce9 to a5923bb Compare November 24, 2026 16:14
@bashtage
bashtage marked this pull request as ready for review November 24, 2026 18:30
@bashtage
bashtage merged commit 5b44168 into statsmodels:main Nov 24, 2026
10 of 11 checks passed
@bashtage
bashtage deleted the wip-tsa-dynamic-date-slice 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