Repository navigation
TST: Cover the statespace smoothers, simulation smoothers and tools - #11025
Merged
Merged
Conversation
This was referenced Nov 22, 2026
bashtage
force-pushed
the
wip-tsa-cov-c9b
branch
2 times, most recently
from
November 23, 2026 22:10
9245421 to
173ba5e
Compare
This was referenced Nov 24, 2026
bashtage
force-pushed
the
wip-tsa-cov-c9b
branch
3 times, most recently
from
November 25, 2026 12:12
3dc779a to
8757189
Compare
Add tests for the untested paths of kalman_smoother.py, simulation_smoother.py, cfa_simulation_smoother.py and tools.py, and for the float64 Cython smoother and simulation smoother paths that the Python layer reaches. Every assertion compares with an independent value: another smoother method or configuration on the same model, the Kalman smoother for the CFA simulation smoother, a closed form, or an identity. - Smoothers: exact diffuse initialization with the alternative and classical smoothers against the conventional smoother; the classical smoother with a singular predicted state covariance; smoothing after conserving memory, univariate smoothing after the conventional filter and an invalid smoothing method raise; subsets of the smoother output equal the full output; a custom results class. - SmootherResults: news() and smoothed_state_gain() with their default periods (checked against the change of the smoothed forecasts and states between two smoother runs), invalid periods, and a partition of the states (impacts and decompositions add up); the default end of smoothed_state_autocovariance() for a negative lag in a time-varying model. - Simulation smoothers: custom and invalid results classes, the simulation output options, generated series against the state space recursions, the nobs errors and a model whose dimensions changed. - CFA simulation smoother: exact diffuse initialization against the Kalman smoother, a single observation and singular covariance matrices raise, the posterior covariance and a draw without updating the posterior, and a pickle round trip. - tools: companion_matrix with a non-identity leading matrix, concat with scalars, Series and invalid input, the defaults of the pure-Python twin helpers against the compiled routine, the prefix of constrain_stationary_multivariate and the copy helpers, the argument errors of the reorder and copy helpers, compute_smoothed_state_weights without period 0, and Initialization.from_components with scalar and vector input.
Make the docstrings of kalman_smoother.py, simulation_smoother.py, cfa_simulation_smoother.py and tools.py match the code. - KalmanSmoother: the default smoother output is 31; set_smooth_method describes the smoothing method (not the filter method), its default of 0 and has working examples; the `prefix` of smooth() is optional. - SmootherResults: `smoothing_error` is the smoothing error vector, not a covariance matrix; the shape and number of extension matrices for forward autocovariances in smoothed_state_autocovariance had the sign of `lag` wrong; smoothed_state_gain accepts any sequence of indices. - Simulation smoother: the deprecated `random_state` keyword was documented as a second `rng`; the Cython simulation smoother parameter showed a template placeholder; the initial state variates are one-dimensional; get_simulation_output gets a Returns section. - CFA simulation smoother: exact diffuse initialization of the whole state vector is supported. - tools: the default threshold of is_invertible, the formula of companion_matrix for a non-identity leading matrix, the return types of concat, diff and is_invertible, `a` of solve_discrete_lyapunov and `polynomial_trend` of prepare_trend_data must be arrays, `nobs` of the shape validators may be None, the summaries and parameter references of the copy helpers, and a reference to a parameter that unconstrain_stationary_multivariate does not have.
This branch is now stacked on statsmodels#11051, which makes constrain_stationary_multivariate (and its public Python twin) return the input variance with transform_variance=False. The private helpers of the twin still return the variance of the internal recursion, so test_python_twin_helpers_default_dimensions failed for transform_variance=False once both were merged (found by merging all open branches and running the test suite). The coefficients are compared in both cases and the variance with transform_variance=True.
bashtage
force-pushed
the
wip-tsa-cov-c9b
branch
from
November 27, 2026 00:32
8757189 to
42010aa
Compare
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.
Stacked on #11051, which is stacked on #11113, #11044, #11047 and #11140: merge those first (this PR adds four commits). The stack was rebuilt on 2026-11-25 so that it merges without conflicts in this order; notes about conflicts with PRs of the same stack no longer apply.
This adds tests for the untested Python paths of
statespace/kalman_smoother.py,simulation_smoother.py,cfa_simulation_smoother.pyandtools.py, and for the float64 Cython smoother and simulation smoother paths that the Python layer reaches (the C14 Cython coverage audit), and makes their docstrings match the code. Every assertion compares with an independent value: another smoother method or configuration on the same model, the Kalman smoother for the CFA simulation smoother, a closed form, or an identity. The source changes are docstrings only.Changes
SmootherResults: default and invalid periods ofnews()andsmoothed_state_gain(), against two smoother runs; impacts and decompositions from a partition of the states add up; the defaultendof forward autocovariances in a time-varying model.nobserrors, a model whose dimensions changed.companion_matrixwith a non-identity leading matrix;concat; the defaults of the pure-Python twins against the compiled routines;prefixarguments; reorder/copy argument errors;compute_smoothed_state_weightswithout period 0;Initialization.from_componentswith scalar and vector input.set_smooth_methodexamples (doctest-checked);smoothing_error; the sign oflaginsmoothed_state_autocovariance; the deprecatedrandom_stateentries; the shape of the initial state variates; CFA diffuse initialization; theis_invertibledefault; thecompanion_matrixformula; the return types ofconcat,diffandis_invertible; array-only parameters; the copy-helper summaries.Not changed
smooth()dropssmooth_methodandcomplex_step;smooth(smoother_output=...)and some output subsets give wrong values;state_indexin the signal decomposition; the cache ofsmoothed_state_autocovariance;compute_smoothed_state_weightson filtered results; the CFA posterior beforesimulate(); ndarray matrix polynomials incompanion_matrix; the returned variance ofconstrain_stationary_multivariate;set_smooth_method(smooth_univariate=True);SmootherResults.smoother_output.Tests
statsmodels/tsa/statespace: 3520 passed, 87 skipped, 34 xfailed, no warnings.Coverage (lines / branches):
kalman_smoother.py93.5/84.8% to 98.1/96.2%;simulation_smoother.py97.3/82.3% to 100/100%;cfa_simulation_smoother.py98.0/71.4% to 98.0/92.9%;tools.py93.7/83.6% to 96.7/92.0%. What remains is reachable only through one of the bugs above, or is listed as a removal candidate.Cython (measured together with TST: Cover the statespace representation, Kalman filter and initialization #11028 on a
-Dcython-coverage=truebuild, Linux, Python 3.12): the tests of the two PRs reach 143 lines of the compiled filters, smoothers, tools, innovations and STL that the full TSA test suite did not; this PR's share is mainly_cfa_simulation_smoother.pyx(+48),_kalman_smoother.pyx(+24) and the smoothers and_tools.pyxargument checks.Mutation check: 35 single-line changes to newly covered lines, all caught.
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: auditing the coverage gaps and docstrings of the statespace smoothers and tools, writing the tests and docstring fixes, and checking them (coverage, 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