Repository navigation
Conversation
bashtage
force-pushed
the
wip-news-revision-impacts-state-index
branch
4 times, most recently
from
November 27, 2026 23:06
ebe3346 to
8caca89
Compare
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
force-pushed
the
wip-news-revision-impacts-state-index
branch
from
November 28, 2026 21:36
8caca89 to
e30221e
Compare
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.
SmootherResults.news (and so MLEResults.news and NewsResults) documents
state_index as "only the impacts to the observed variables arising from
the impacts to [these] states". update_impacts and
revision_detailed_impacts used the subset of states, but revision_impacts,
the total impact of the revisions, was the difference of the smoothed
forecasts after and before the revisions, through all states. So the
"impact of revisions" and "total impact" columns of NewsResults.impacts,
and the grouped revision impacts ("all prior revisions",
revision_impacts - revision_detailed_impacts), counted the impacts through
the other states. For the VAR(1) of the new test (identity design
matrix) with state_index=[0], the news impacts and the detailed revision
impacts on the second variable (unemp) were 0, but its revision impacts
were those through all states: 8.1 and 9.2 in 2009Q1 and 2009Q2 (its own
revisions from 0) and 6.5 to 8.1 in the following periods.
Changes
- With state_index, revision_impacts is the design matrix of those states
times the revisions of those smoothed states (the smoothed states of
the revision results less those of the previous results, which are the
predicted states after the sample), for every impact period, also with a
time-varying design matrix.
- versionchanged in the state_index docstring; the revision_impacts entry
says that it follows state_index.
Results of news calls with state_index change: revision_impacts, the
grouped revision impacts, and the "impact of revisions" and "total
impact" columns of the impacts table (and rows of variables without
impacts through the given states are left out of it).
Not changed
- news without state_index (the forecasts are used as before), and the
estimates before and after (prev_impacted_forecasts,
post_impacted_forecasts), which remain those of all states.
Tests
- test_state_index_revision_impacts: in the VAR(1) with revisions of two
periods and impacts through three periods after the sample, with all
revisions detailed, all grouped, or those of one period grouped, the
revision, detailed, grouped and news impacts through the state of each
variable are the full impacts on that variable and zero on the other,
and the impacts table has only that variable's rows; both states
together give the impacts without state_index. Fails on the previous
commit (the revision and grouped impacts on the other variable).
- test_state_index_revision_impacts_time_varying_design: for a SARIMAX
with the regression coefficient as a state (design [1, x_t]) and a new
last value (so that the impacts include a period after the previous
sample), the revision impacts through the AR state and through the
coefficient add up to the impacts without state_index, and each agrees
with the detailed impacts, which are computed from the smoothed state
weights.
Fails on the previous commit.
bashtage
force-pushed
the
wip-news-revision-impacts-state-index
branch
from
November 28, 2026 22:06
e30221e to
128c214
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 #11054, merge that first (its commits are the first ones here; this PR adds one commit): both change the total revision impacts in
SmootherResults.news. No conflict inkalman_smoother.pywith #11025, #11044-#11047, #11052 or #11113 (#11054 conflicts with some of them only intest_smoothing.py, where both append).test_news.pyconflicts with #11078 (and #11080-#11082, #11118, #11119 stacked on it) and the NewsResults weights PR only where both append tests at the end of the file: keep both blocks.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
was just re-created. _smooth is only called by smooth() right after
_filter() with the same arguments, so neither is ever re-created.
extend_kwargs is Nonedefault. Its only caller always passes a dict, so the argument isnow required.
revision impacts. The revision model is built through
max(end, previous.nobs), so
endnever exceeds its sample.tools.py
k_endog < 1check. A zerok_endog fails earlier, in
order //= k_endog.orderandk_endog(always passed); they are now required.
orderandk_endogarguments, which no caller passes (k_endog was not used).orderandk_endogarguments, which were recomputed from the matrices, and the branch for an
array of matrices (its only caller passes a list).
of matrices and the
forward_autocovariancesargument (its only callerpasses a list and backward autocovariances). The existing direct test
passes lists and does not change.
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 takes one input and returns its array, and _atleast_2d
always returns a list.
simulation_smoother.py
template-literal class
_{{prefix}}Representation; it now says "theunderlying 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
designas the design matrixfor period
tthat a time-varying model needs whentis outside of itssample. 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
designcould not be reached.Changes:
designraises a FutureWarning; it will be removed afterstatsmodels 0.18 is released. The docstring says that it is not used.
designare 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
designequal the change in the smoothedforecasts that the new observations cause.
BUG: Restrict the revision impacts of the news to state_index
SmootherResults.news (and so MLEResults.news and NewsResults) documents
state_index as "only the impacts to the observed variables arising from
the impacts to [these] states". update_impacts and
revision_detailed_impacts used the subset of states, but revision_impacts,
the total impact of the revisions, was the difference of the smoothed
forecasts after and before the revisions, through all states. So the
"impact of revisions" and "total impact" columns of NewsResults.impacts,
and the grouped revision impacts ("all prior revisions",
revision_impacts - revision_detailed_impacts), counted the impacts through
the other states. For the VAR(1) of the new test (identity design
matrix) with state_index=[0], the news impacts and the detailed revision
impacts on the second variable (unemp) were 0, but its revision impacts
were those through all states: 8.1 and 9.2 in 2009Q1 and 2009Q2 (its own
revisions from 0) and 6.5 to 8.1 in the following periods.
Changes
times the revisions of those smoothed states (the smoothed states of
the revision results less those of the previous results, which are the
predicted states after the sample), for every impact period, also with a
time-varying design matrix.
says that it follows state_index.
Results of news calls with state_index change: revision_impacts, the
grouped revision impacts, and the "impact of revisions" and "total
impact" columns of the impacts table (and rows of variables without
impacts through the given states are left out of it).
Not changed
estimates before and after (prev_impacted_forecasts,
post_impacted_forecasts), which remain those of all states.
Tests
test_state_index_revision_impacts: in the VAR(1) with revisions of two
periods and impacts through three periods after the sample, with all
revisions detailed, all grouped, or those of one period grouped, the
revision, detailed, grouped and news impacts through the state of each
variable are the full impacts on that variable and zero on the other,
and the impacts table has only that variable's rows; both states
together give the impacts without state_index. Fails on the previous
commit (the revision and grouped impacts on the other variable).
test_state_index_revision_impacts_time_varying_design: for a SARIMAX
with the regression coefficient as a state (design [1, x_t]) and a new
last value (so that the impacts include a period after the previous
sample), the revision impacts through the AR state and through the
coefficient add up to the impacts without state_index, and each agrees
with the detailed impacts, which are computed from the smoothed state
weights.
Fails on the previous commit.
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: 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