Repository navigation
Conversation
4 of 5 tasks
bashtage
force-pushed
the
wip-ss-predict-unknown-kwargs
branch
from
November 27, 2026 00:31
369cea5 to
904beb3
Compare
…ediction The prediction methods of the state space models pass their extra keyword arguments to FilterResults.predict. Dynamic prediction and out-of-sample forecasting rerun the Kalman filter with an extended model created with them, whose constructor raises "TypeError: Unknown keyword arguments: [...]" for any it does not use. In-sample prediction does not rerun the filter and silently ignored them, so res.get_prediction(typo_keyword=1) ran while res.get_prediction(typo_keyword=1, dynamic=10) raised, for SARIMAX, UnobservedComponents, VARMAX, DynamicFactorMQ, RecursiveLS and every other MLEModel. A misspelled keyword was dropped only when no filter was rerun. Changes - In-sample FilterResults.predict, and so get_prediction and predict of the results of every state space model, emits a FutureWarning for keyword arguments that the state space model does not use. They will raise a TypeError after statsmodels 0.17 is released. The warning repeats the message of the TypeError of the rerun, for example "Unknown keyword arguments: ['typo_keyword']." - "Unknown" is decided by the same check as in the rerun: a model of the same class (KalmanFilter, KalmanSmoother or SimulationSmoother) is created with the keyword arguments, and its constructor raises that TypeError. The keyword arguments that the extended model of the rerun always accepts are left out of this check: the system matrices (time-varying matrices for the extension do not warn), the dimensions, which it takes from the model, and the initialization, which predict sets. Invalid values of known options, which raise other errors in the rerun, are ignored in sample as before. - The warning is attributed to the first caller outside statsmodels. - deprecated directives in the kwargs descriptions of FilterResults.predict, MLEResults.get_prediction and MLEResults.predict. Not changed - get_forecast, forecast and out-of-sample or dynamic get_prediction and predict, which already raised the TypeError, and simulate, which creates the extended model also in sample and so already raised it there. - Known keyword arguments in sample (system matrices, filter options such as conserve_memory or tolerance) do not warn. - RecursiveLSResults.get_prediction has no extend_model argument, so get_prediction(extend_model=True) in sample now warns (it raised out of sample). Tests - For SARIMAX, UnobservedComponents, VARMAX and RecursiveLS, through get_prediction and predict: an unknown keyword, the observation array "obs" and "initial_state" (both not accepted by the extended model), and an unknown keyword together with each of the keywords that the check leaves out, warn in sample with the message of the TypeError, give the predictions of the call without them, and raise the TypeError with dynamic=10 (except with a system matrix, for which dynamic prediction raises a ValueError). Fail on main (no warning). - Known keywords (conserve_memory, tolerance, constant and stationary_cov, and invalid values of alternate_timing and timing_init_filtered) do not warn and do not change the predictions. - RecursiveLS: a time-varying design for the extension does not warn in sample and gives the forecasts (the sum of the coefficients for a design of ones); extend_model and FilterResults.predict warn.
The RecursiveLS prediction test checks that the FutureWarning for unknown keyword arguments of in-sample prediction is attributed to the calling test module, for RecursiveLSResults.get_prediction and for FilterResults.predict.
bashtage
force-pushed
the
wip-ss-predict-unknown-kwargs
branch
from
November 28, 2026 21:36
904beb3 to
aa1fdf6
Compare
The release after 0.15.0 is 0.16.0, not 0.15.1, so unknown keyword arguments of in-sample prediction are deprecated in 0.16.0. Move the change to a TypeError one release later, to after statsmodels 0.18 is released, as xref statsmodels#11327 does for the deprecations that named 0.17.
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.
Implements decision 78 (a): a FutureWarning for unknown keyword arguments of in-sample get_prediction and predict of the state space models, a TypeError after statsmodels 0.18. This also covers RecursiveLS get_prediction(extend_model=...) (QB J6). kalman_filter.py and mlemodel.py merge cleanly with every open PR that changes them (#11141, #11152, #11159, #11162, #11165, #11169 and the others); test_prediction.py conflicts with #11037 in the imports and only where both append tests at the end of the file: keep both blocks.
DEP: Warn about unknown keyword arguments of in-sample state space prediction
The prediction methods of the state space models pass their extra keyword
arguments to FilterResults.predict. Dynamic prediction and out-of-sample
forecasting rerun the Kalman filter with an extended model created with
them, whose constructor raises "TypeError: Unknown keyword arguments: [...]"
for any it does not use. In-sample prediction does not rerun the filter
and silently ignored them, so res.get_prediction(typo_keyword=1) ran while
res.get_prediction(typo_keyword=1, dynamic=10) raised, for SARIMAX,
UnobservedComponents, VARMAX, DynamicFactorMQ, RecursiveLS and every other
MLEModel. A misspelled keyword was dropped only when no filter was rerun.
Changes
the results of every state space model, emits a FutureWarning for
keyword arguments that the state space model does not use. They will
raise a TypeError after statsmodels 0.18 is released. The warning
repeats the message of the TypeError of the rerun, for example
"Unknown keyword arguments: ['typo_keyword']."
same class (KalmanFilter, KalmanSmoother or SimulationSmoother) is
created with the keyword arguments, and its constructor raises that
TypeError. The keyword arguments that the extended model of the rerun
always accepts are left out of this check: the system matrices
(time-varying matrices for the extension do not warn), the dimensions,
which it takes from the model, and the initialization, which predict
sets. Invalid values of known options, which raise other errors in the
rerun, are ignored in sample as before.
FilterResults.predict, MLEResults.get_prediction and MLEResults.predict.
Not changed
predict, which already raised the TypeError, and simulate, which
creates the extended model also in sample and so already raised it
there.
as conserve_memory or tolerance) do not warn.
get_prediction(extend_model=True) in sample now warns (it raised
out of sample).
Tests
get_prediction and predict: an unknown keyword, the observation array
"obs" and "initial_state" (both not accepted by the extended model), and
an unknown keyword together with each of the keywords that the check
leaves out, warn in sample with the message of the TypeError, give the
predictions of the call without them, and raise the TypeError with
dynamic=10 (except with a system matrix, for which dynamic prediction
raises a ValueError). Fail on main (no warning).
stationary_cov, and invalid values of alternate_timing and
timing_init_filtered) do not warn and do not change the predictions.
sample and gives the forecasts (the sum of the coefficients for a
design of ones); extend_model and FilterResults.predict warn.
TST: Check that the unknown keyword warning points at the caller
The RecursiveLS prediction test checks that the FutureWarning for unknown
keyword arguments of in-sample prediction is attributed to the calling
test module, for RecursiveLSResults.get_prediction and for
FilterResults.predict.
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: implementing the maintainer's decision, writing the tests against independent values, 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