Skip to content

DEP: Warn about unknown keyword arguments of in-sample state space prediction - #11185

Draft
bashtage wants to merge 4 commits into
statsmodels:mainfrom
bashtage:wip-ss-predict-unknown-kwargs
Draft

bashtage wants to merge 4 commits into
statsmodels:mainfrom
bashtage:wip-ss-predict-unknown-kwargs

Conversation

@bashtage

@bashtage bashtage commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

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

  • 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.18 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.

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.

  • 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: 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

…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
bashtage force-pushed the wip-ss-predict-unknown-kwargs branch from 904beb3 to aa1fdf6 Compare November 28, 2026 21:36
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.
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