Repository navigation
DOC: Say that the end of FilterResults.predict is excluded - #11117
Merged
Merged
Conversation
The docstring of `FilterResults.predict` said that "the last prediction will be at end", but `end` is excluded, as the end of a slice: for a model with 20 observations, `predict(start=2, end=5)` returns the 3 predictions for periods 2, 3 and 4, `predict()` (whose default `end` is the number of observations) returns the 20 in-sample predictions, and `predict(start=18, end=22)` returns 2 in-sample predictions and 2 out-of-sample forecasts. The `end` parameter and attribute of `PredictionResults`, which receive this `end`, and the private `_check_dynamic` had the same mistake. Changes - The `end` parameter of `FilterResults.predict` says that it is excluded, with its default. - The same for the `end` parameter and attribute of `PredictionResults`, and for `end` of `_check_dynamic`. Not changed - The code. (`nforecast` of `PredictionResults` is documented as the number of in-sample forecasts, but statsmodels#11028 already fixes that.)
This was referenced Nov 24, 2026
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. |
bashtage
marked this pull request as ready for review
November 24, 2026 14:49
bashtage
added a commit
that referenced
this pull request
Nov 24, 2026
_check_dynamic is called by FilterResults.predict and by STLForecastResults. #11117 changed the description of its `end` from the location of the final forecast (inclusive) to the location after it (exclusive), which is what FilterResults.predict passes (for example 48 for in-sample predictions that end at observation 47 of 48, and 51 with three out-of-sample forecasts). STLForecastResults passes the location of the final in-sample forecast (inclusive), 47 in both cases, and does not use the returned number of dynamic forecasts (which is one short for it). Changes - The `end` of _check_dynamic says what each caller passes, and that dynamic prediction beginning after `end` has no effect. - ndynamic is the number of in-sample dynamic forecasts for an exclusive `end`, min(end, nobs) - dynamic. - The comment in FilterResults.predict describes the ranges [0, end) and [start, end), as `end` is excluded. Not changed - Any behavior.
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.
Docstrings only. No conflict in
kalman_filter.pywith #11028 (which fixesnforecastin the same docstring), #11035-#11037, #11039 or #11071-#11073.The docstring of
FilterResults.predictsaid that "the last predictionwill be at end", but
endis excluded, as the end of a slice: for amodel with 20 observations,
predict(start=2, end=5)returns the 3predictions for periods 2, 3 and 4,
predict()(whose defaultendis thenumber of observations) returns the 20 in-sample predictions, and
predict(start=18, end=22)returns 2 in-sample predictions and 2out-of-sample forecasts. The
endparameter and attribute ofPredictionResults, which receive thisend, and the private_check_dynamichad the same mistake.Changes
endparameter ofFilterResults.predictsays that it is excluded,with its default.
endparameter and attribute ofPredictionResults,and for
endof_check_dynamic.Not changed
The code. (
nforecastofPredictionResultsis documented as thenumber of in-sample forecasts, but TST: Cover the statespace representation, Kalman filter and initialization #11028 already fixes that.)
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: checking the docstring against the code (predictions for several start and end values) and writing the docstring fix.
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