Repository navigation
Conversation
This was referenced Nov 23, 2026
bashtage
force-pushed
the
wip-ss-prediction-forecasts-cov
branch
from
November 27, 2026 00:31
2da16b5 to
3505d17
Compare
Two bugs in `statsmodels.tsa.statespace.kalman_filter.PredictionResults` (the result of `FilterResults.predict`, also held by `MLEResults.get_prediction(...).prediction_results`): - `filtered_forecasts_error_cov` and `smoothed_forecasts_error_cov` returned None when read before `filtered_forecasts` / `smoothed_forecasts`. The properties cache the covariances in `_filtered_forecasts_cov` / `_smoothed_forecasts_cov`, but `__init__` set `_filtered_forecasts_error_cov` / `_smoothed_forecasts_error_cov` instead. Reading the unset cache raised AttributeError inside the property, so Python fell back to `__getattr__`, which returned the None of the wrongly named attribute. - `npredictions` was `start - end`, a negative number, instead of the number of predicted periods `end - start` (`end` is exclusive here). Changes: `__init__` sets the caches the properties use, and `npredictions = end - start`, with a `versionchanged` note in the docstring. Not changed: the values of the forecasts and covariances when the means were read first (the path `MLEResults.get_prediction` uses), and the other attributes. Tests: for the filtered and smoothed information sets, reading the covariances before or after the means, in sample and with forecasts beyond the sample, the forecasts equal d + Z a_t and the forecast error covariances Z P_t Z' + H computed from the predicted states, and `npredictions` equals `end - start` and the number of predicted periods. All 8 new tests fail on main.
bashtage
force-pushed
the
wip-ss-prediction-forecasts-cov
branch
from
November 28, 2026 21:36
3505d17 to
c9a604e
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.
Two bugs in
statsmodels.tsa.statespace.kalman_filter.PredictionResults(the result of
FilterResults.predict, also held byMLEResults.get_prediction(...).prediction_results):filtered_forecasts_error_covandsmoothed_forecasts_error_covreturned None when read before
filtered_forecasts/smoothed_forecasts. The properties cache the covariances in_filtered_forecasts_cov/_smoothed_forecasts_cov, but__init__set
_filtered_forecasts_error_cov/_smoothed_forecasts_error_covinstead. Reading the unset cache raised AttributeError inside the
property, so Python fell back to
__getattr__, which returned theNone of the wrongly named attribute.
npredictionswasstart - end, a negative number, instead of thenumber of predicted periods
end - start(endis exclusive here).Changes:
__init__sets the caches the properties use, andnpredictions = end - start, with aversionchangednote in thedocstring.
Not changed: the values of the forecasts and covariances when the means
were read first (the path
MLEResults.get_predictionuses), and theother attributes.
Tests: for the filtered and smoothed information sets, reading the
covariances before or after the means, in sample and with forecasts
beyond the sample, the forecasts equal d + Z a_t and the forecast error
covariances Z P_t Z' + H computed from the predicted states, and
npredictionsequalsend - startand the number of predicted periods.All 8 new tests fail on main.
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: finding the bug in a contract audit, writing the fix and its tests, and checking them (tests failing on main, 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