Repository navigation
BUG: Pass extend_kwargs on in VARMAXResults.get_prediction - #11167
Merged
bashtage merged 2 commits intoNov 24, 2026
Merged
Conversation
4 of 5 tasks
Member
Author
|
Merge order. These open PRs build on this one (their branches contain its commits), so please merge this PR first: 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. |
4 of 5 tasks
VARMAXResults.get_prediction built its own extend_kwargs (the trend
offset of the model of the forecast periods) and passed it to
MLEResults.get_prediction together with **kwargs, so any call with
extend_kwargs, documented in the shared docstring, raised "TypeError:
MLEResults.get_prediction() got multiple values for keyword argument
'extend_kwargs'", also extend_kwargs={}. get_forecast, forecast and
predict call get_prediction and raised as well.
Changes
- get_prediction takes extend_kwargs and passes it on.
- The trend offset that VARMAX set is dropped: the shared code that builds
the extended model (_get_extension_time_varying_matrices) sets the same
default, trend_offset + nobs, with setdefault. A key given in
extend_kwargs therefore wins over the default, as for every other state
space model and as in VARMAXResults.extend.
Not changed
- Results without extend_kwargs: the predictions, their variances, the
dynamic predictions and the forecasts of 60 VARMAX specifications (each
trend with 0, 1 and 2 exog, two orders, two trend offsets) are identical
to main.
- simulate (of the results and of the model) passed extend_kwargs on
already; with zero shocks it equals the forecast for both an empty
extend_kwargs and a trend_offset.
Tests
- VARMAX(1, 0) with a linear trend, without and with exog, at fixed
parameters: get_forecast, forecast, predict and get_prediction with an
empty extend_kwargs and with a trend_offset equal the forecasts computed
by hand from the VAR recursion (the trend values after the first forecast
come from the trend_offset). Every case fails on main.
bashtage
force-pushed
the
wip-varmax-prediction-extend-kwargs
branch
from
November 24, 2026 16:17
350f5df to
d76f506
Compare
bashtage
added a commit
to bashtage/statsmodels
that referenced
this pull request
Nov 24, 2026
The out-of-sample extension of state space models set its defaults with setdefault on the extend_kwargs dict that the caller passed: the trend offset of the extended model (MLEModel, used by VARMAX since statsmodels#11167, and SARIMAX) and validate_specification=False (SARIMAX). Reusing that dict for another model, or for the same model after append/extend, silently used the first model's trend offset. For example, with ek = {}, SARIMAX(y, exog=x[:40], order=(1, 0, 0), trend="t") .smooth([.1, .5, .3, 1]).get_forecast(3, exog=x[40:], extend_kwargs=ek) and then the 30-observation model's forecast(3, exog=x[30:33], extend_kwargs=ek) gave [3.42, 5.46, 6.24] instead of [3.42, 4.46, 4.94]. Stacked on statsmodels#11167, which makes VARMAX pass extend_kwargs on to the shared MLEModel code (before, VARMAX raised for any extend_kwargs). Changes - MLEModel._get_extension_time_varying_matrices and SARIMAX._get_extension_time_varying_matrices copy extend_kwargs before setting their defaults. - A versionchanged note under extend_kwargs in MLEResults.get_prediction (shared by the SARIMAX and VARMAX docstrings). Tests (test_forecasting.py) - SARIMAX with a time trend and exog, and VARMAX with "ct" and exog: the dict passed to get_forecast of a 40-observation model stays empty, and the forecasts of a 30-observation model with that dict equal its forecasts without extend_kwargs. The SARIMAX case fails with the old sarimax.py, the VARMAX case with the old mlemodel.py.
bashtage
marked this pull request as ready for review
November 24, 2026 18:46
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No other open PR changes VARMAXResults.get_prediction. A key given in extend_kwargs wins over the default trend_offset, as in the shared code (_get_extension_time_varying_matrices uses setdefault) and in VARMAXResults.extend. That shared code writes the default trend_offset into the caller's dict (on main also for SARIMAX and the other models; a separate fix). varmax.py merges cleanly with every open PR that changes it (#11083, #11085-#11089, #11103, #11121, #11133, #11157, #11162); test_varmax.py conflicts with #11083, #11085-#11089, #11103, #11121, #11133 and #11157 only where both append tests at the end: keep both blocks.
VARMAXResults.get_prediction built its own extend_kwargs (the trend
offset of the model of the forecast periods) and passed it to
MLEResults.get_prediction together with **kwargs, so any call with
extend_kwargs, documented in the shared docstring, raised "TypeError:
MLEResults.get_prediction() got multiple values for keyword argument
'extend_kwargs'", also extend_kwargs={}. get_forecast, forecast and
predict call get_prediction and raised as well.
Changes
the extended model (_get_extension_time_varying_matrices) sets the same
default, trend_offset + nobs, with setdefault. A key given in
extend_kwargs therefore wins over the default, as for every other state
space model and as in VARMAXResults.extend.
Not changed
dynamic predictions and the forecasts of 60 VARMAX specifications (each
trend with 0, 1 and 2 exog, two orders, two trend offsets) are identical
to main.
already; with zero shocks it equals the forecast for both an empty
extend_kwargs and a trend_offset.
Tests
VARMAX(1, 0) with a linear trend, without and with exog, at fixed
parameters: get_forecast, forecast, predict and get_prediction with an
empty extend_kwargs and with a trend_offset equal the forecasts computed
by hand from the VAR recursion (the trend values after the first forecast
come from the trend_offset). Every case fails 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.
Tool(s): Claude Code (Claude Opus 5.5).
Used for: finding the bug in a coverage audit of the time series code, writing the fix and its tests, and checking them (tests failing on the base, 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