Skip to content

DOC: Say that the end of FilterResults.predict is excluded - #11117

Merged
bashtage merged 2 commits into
statsmodels:mainfrom
bashtage:wip-ss-predict-end-doc
Nov 24, 2026
Merged

bashtage merged 2 commits into
statsmodels:mainfrom
bashtage:wip-ss-predict-end-doc

Conversation

@bashtage

Copy link
Copy Markdown
Member

Docstrings only. No conflict in kalman_filter.py with #11028 (which fixes nforecast in the same docstring), #11035-#11037, #11039 or #11071-#11073.

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

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: 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

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.)
@bashtage

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.

@bashtage
bashtage marked this pull request as ready for review November 24, 2026 14:49
@bashtage
bashtage merged commit 22bda49 into statsmodels:main Nov 24, 2026
11 of 12 checks passed
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.
@bashtage
bashtage deleted the wip-ss-predict-end-doc branch November 24, 2026 18:28
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