Skip to content

REF: Remove unreachable smoother code, deprecate news(design=...) - #11054

Draft
bashtage wants to merge 4 commits into
statsmodels:mainfrom
bashtage:wip-ss-smoother-unreachable
Draft

bashtage wants to merge 4 commits into
statsmodels:mainfrom
bashtage:wip-ss-smoother-unreachable

Conversation

@bashtage

@bashtage bashtage commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Two commits; the details are in each. Based on main; #11025 (the C9b coverage chunk) changes docstrings of the same files and appends to the same test files, so whichever merges second needs a rebase. With #11025: only test_smoothing.py, keep both blocks. The other C9F-B PRs that append to test_smoothing.py (smooth arguments, smoother output, autocovariance cache, smoother unreachable code) conflict there too: keep every appended block and the union of the imports.

REF: Remove unreachable code in the statespace smoother and tools

Code that no public path reaches (found by the C9b coverage work on
kalman_smoother.py, tools.py and simulation_smoother.py):

kalman_smoother.py

  • KalmanSmoother._smooth: the check that the filter or the representation
    was just re-created. _smooth is only called by smooth() right after
    _filter() with the same arguments, so neither is ever re-created.
  • SmootherResults._smoothed_state_autocovariance: the extend_kwargs is None default. Its only caller always passes a dict, so the argument is
    now required.
  • SmootherResults.news: the out-of-sample prediction for the total
    revision impacts. The revision model is built through
    max(end, previous.nobs), so end never exceeds its sample.

tools.py

  • constrain_stationary_multivariate: the k_endog < 1 check. A zero
    k_endog fails earlier, in order //= k_endog.
  • _unconstrain_sv_less_than_one: the defaults of order and k_endog
    (always passed); they are now required.
  • _compute_multivariate_pacf_from_autocovariances: the order and
    k_endog arguments, which no caller passes (k_endog was not used).
  • _compute_multivariate_pacf_from_coefficients: the order and k_endog
    arguments, which were recomputed from the matrices, and the branch for an
    array of matrices (its only caller passes a list).
  • _compute_multivariate_acovf_from_coefficients: the branch for an array
    of matrices and the forward_autocovariances argument (its only caller
    passes a list and backward autocovariances). The existing direct test
    passes lists and does not change.
  • copy_missing_matrix, copy_missing_vector, copy_index_matrix and
    copy_index_vector: the blocks that kept an F-contiguous Cython
    memoryview unconverted. All callers pass ndarrays, so the source is
    always converted with np.require, as before.
  • _atleast_1d is only called with one input and _atleast_2d with five, so
    _atleast_1d takes one input and returns its array, and _atleast_2d
    always returns a list.

simulation_smoother.py

  • The simulate() error for a changed representation named the
    template-literal class _{{prefix}}Representation; it now says "the
    underlying compiled representation model object".

Not changed: results and errors of all public functions.
_safe_cond keeps its inf branch: with numpy's own LAPACK, np.linalg.cond
only fails for NaN entries, but other LAPACK builds may fail to converge
for inf entries.

Tests: no new tests; the statespace suite passes. Coverage of the
statespace tests: kalman_smoother.py 93.5/84.8% to 94.3/85.7% (lines /
branches), tools.py 93.7/83.6% to 96.4/90.4%.

DEP: Deprecate the unused design argument of SmootherResults.news

SmootherResults.news(design=...) documented design as the design matrix
for period t that a time-varying model needs when t is outside of its
sample. It had no effect: news raises a RuntimeError for impacts on
periods outside of the sample of a time-varying model, and otherwise the
design matrix of the results object is used, so the branches that read
design could not be reached.

Changes:

  • Passing design raises a FutureWarning; it will be removed after
    statsmodels 0.18 is released. The docstring says that it is not used.
  • The unreachable branches that read design are removed.

Not changed: the results of news, with or without design.

Tests (appended to test_smoothing.py): for a time-invariant and a
time-varying model, news(design=...) warns, from the caller, and the
update impacts with and without design equal the change in the smoothed
forecasts that the new observations cause.

  • 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 unreachable code in a coverage audit, removing it, deprecating the argument that has no effect, writing the tests, and checking that results do not change.
    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 24, 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:

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 (updated 2026-11-25).

@bashtage
bashtage force-pushed the wip-ss-smoother-unreachable branch 4 times, most recently from 4a1657b to 071bf2d Compare November 27, 2026 23:06
Code that no public path reaches (found by the C9b coverage work on
kalman_smoother.py, tools.py and simulation_smoother.py):

kalman_smoother.py
- KalmanSmoother._smooth: the check that the filter or the representation
  was just re-created. _smooth is only called by smooth() right after
  _filter() with the same arguments, so neither is ever re-created.
- SmootherResults._smoothed_state_autocovariance: the `extend_kwargs is
  None` default. Its only caller always passes a dict, so the argument is
  now required.
- SmootherResults.news: the out-of-sample prediction for the total
  revision impacts. The revision model is built through
  max(end, previous.nobs), so `end` never exceeds its sample.

tools.py
- constrain_stationary_multivariate: the `k_endog < 1` check. A zero
  k_endog fails earlier, in `order //= k_endog`.
- _unconstrain_sv_less_than_one: the defaults of `order` and `k_endog`
  (always passed); they are now required.
- _compute_multivariate_pacf_from_autocovariances: the `order` and
  `k_endog` arguments, which no caller passes (k_endog was not used).
- _compute_multivariate_pacf_from_coefficients: the `order` and `k_endog`
  arguments, which were recomputed from the matrices, and the branch for an
  array of matrices (its only caller passes a list).
- _compute_multivariate_acovf_from_coefficients: the branch for an array
  of matrices and the `forward_autocovariances` argument (its only caller
  passes a list and backward autocovariances). The existing direct test
  passes lists and does not change.
- copy_missing_matrix, copy_missing_vector, copy_index_matrix and
  copy_index_vector: the blocks that kept an F-contiguous Cython
  memoryview unconverted. All callers pass ndarrays, so the source is
  always converted with np.require, as before.
- _atleast_1d is only called with one input and _atleast_2d with five, so
  _atleast_1d takes one input and returns its array, and _atleast_2d
  always returns a list.

simulation_smoother.py
- The simulate() error for a changed representation named the
  template-literal class `_{{prefix}}Representation`; it now says "the
  underlying compiled representation model object".

Not changed: results and errors of all public functions.
_safe_cond keeps its inf branch: with numpy's own LAPACK, np.linalg.cond
only fails for NaN entries, but other LAPACK builds may fail to converge
for inf entries.

Tests: no new tests; the statespace suite passes. Coverage of the
statespace tests: kalman_smoother.py 93.5/84.8% to 94.3/85.7% (lines /
branches), tools.py 93.7/83.6% to 96.4/90.4%.
SmootherResults.news(design=...) documented `design` as the design matrix
for period `t` that a time-varying model needs when `t` is outside of its
sample. It had no effect: news raises a RuntimeError for impacts on
periods outside of the sample of a time-varying model, and otherwise the
design matrix of the results object is used, so the branches that read
`design` could not be reached.

Changes:
- Passing `design` raises a FutureWarning; it will be removed after
  statsmodels 0.17 is released. The docstring says that it is not used.
- The unreachable branches that read `design` are removed.

Not changed: the results of news, with or without `design`.

Tests (appended to test_smoothing.py): for a time-invariant and a
time-varying model, news(design=...) warns, from the caller, and the
update impacts with and without `design` equal the change in the smoothed
forecasts that the new observations cause.
@bashtage
bashtage force-pushed the wip-ss-smoother-unreachable branch from 071bf2d to c7332e2 Compare November 28, 2026 21:36
The release after 0.15.0 is 0.16.0, not 0.15.1, so the design argument
is deprecated in 0.16.0. Move its removal 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