Skip to content

DOC: Say which end each caller passes to _check_dynamic - #11165

Merged
bashtage merged 3 commits into
statsmodels:mainfrom
bashtage:wip-ss-check-dynamic-end-doc
Nov 24, 2026
Merged

bashtage merged 3 commits into
statsmodels:mainfrom
bashtage:wip-ss-check-dynamic-end-doc

Conversation

@bashtage

Copy link
Copy Markdown
Member

Stacked on #11117, merge that first (its commits are the first ones here; this PR adds one commit). It rewrites the line of _check_dynamic that #11117 changes. Merges cleanly with the other open kalman_filter.py PRs (#11035, #11036, #11037, #11116, #11141, #11152, #11159). No release note: the docstring of a private function and a comment.

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

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

DOC: Say which end each caller passes to _check_dynamic

_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.

  • 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: checking which end each caller passes and writing the docstring.
    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.)
_check_dynamic is called by FilterResults.predict and by
STLForecastResults. statsmodels#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 marked this pull request as ready for review November 24, 2026 14:50
@bashtage
bashtage merged commit d34c195 into statsmodels:main Nov 24, 2026
10 of 11 checks passed
@bashtage
bashtage deleted the wip-ss-check-dynamic-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