Skip to content

BUG: Accept numpy integer impulses and deprecate direct - #11039

Merged
bashtage merged 3 commits into
statsmodels:mainfrom
bashtage:wip-ss-impulse-integer
Nov 23, 2026
Merged

bashtage merged 3 commits into
statsmodels:mainfrom
bashtage:wip-ss-impulse-integer

Conversation

@bashtage

Copy link
Copy Markdown
Member

Two commits; the details are in each. Based on main; #11028 (the C9a coverage chunk) changes docstrings of the same file and appends to the same test files, so whichever merges second needs a rebase. With #11028 in the impulse_responses docstring: keep its impulse wording and its "direct ... Not used." text, plus this PR's versionchanged and deprecated blocks.

BUG: Accept NumPy integers as the impulse of state space impulse responses

KalmanFilter.impulse_responses recognized an index only with
type(impulse) is int, so a NumPy integer (for example an element of
np.arange or an index found with np.argmax) was treated as an
impulse vector and raised "Invalid impulse vector. Must be shaped
(k_posdef,)". MLEModel.impulse_responses and
MLEResults.impulse_responses pass impulse through, so they raised
too.

Changes: Python and NumPy integers are indexes; a bool is still not
(it raised before and still raises "Invalid impulse vector"), and a
NumPy integer out of range raises the same "Invalid value for
impulse" error as a Python int. versionchanged note in the
docstring.

Not changed: impulse vectors, Python int indexes, and the responses.

Tests: NumPy int64, int32 and uint8 indexes give the closed-form
responses Z T^h R e_j of a bivariate model with non-diagonal design,
transition and selection, through the state space model and through
MLEResults.impulse_responses, and a Python int still does; a bool and
out-of-range NumPy integers raise. 10 of the 11 new tests fail on main
(the bool case is unchanged).

DEP: Deprecate the unused direct argument of KalmanFilter.impulse_responses

direct was added in cce58ac, the commit that removed the direct
(closed-form) computation of impulse responses for time-invariant
systems, and it has never been used: the responses are always computed
by simulation. It was not documented.

Changes: direct defaults to None, and giving it (True or False) emits
a FutureWarning saying that it is not used and will be removed after
statsmodels 0.17 is released. It is documented as deprecated.

Not changed: the responses, with or without direct; no warning when it
is not given (MLEModel.impulse_responses never passes it).

Tests: direct=True and direct=False warn (pointing to the caller) and
give the closed-form responses, and no warning is emitted without
direct. Both new tests fail on main.

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

…onses

`KalmanFilter.impulse_responses` recognized an index only with
`type(impulse) is int`, so a NumPy integer (for example an element of
`np.arange` or an index found with `np.argmax`) was treated as an
impulse vector and raised "Invalid impulse vector. Must be shaped
(k_posdef,)". `MLEModel.impulse_responses` and
`MLEResults.impulse_responses` pass `impulse` through, so they raised
too.

Changes: Python and NumPy integers are indexes; a bool is still not
(it raised before and still raises "Invalid impulse vector"), and a
NumPy integer out of range raises the same "Invalid value for
`impulse`" error as a Python int. `versionchanged` note in the
docstring.

Not changed: impulse vectors, Python int indexes, and the responses.

Tests: NumPy int64, int32 and uint8 indexes give the closed-form
responses Z T^h R e_j of a bivariate model with non-diagonal design,
transition and selection, through the state space model and through
`MLEResults.impulse_responses`, and a Python int still does; a bool and
out-of-range NumPy integers raise. 10 of the 11 new tests fail on main
(the bool case is unchanged).
…ponses

`direct` was added in cce58ac, the commit that removed the direct
(closed-form) computation of impulse responses for time-invariant
systems, and it has never been used: the responses are always computed
by simulation. It was not documented.

Changes: `direct` defaults to None, and giving it (True or False) emits
a FutureWarning saying that it is not used and will be removed after
statsmodels 0.17 is released. It is documented as deprecated.

Not changed: the responses, with or without `direct`; no warning when it
is not given (`MLEModel.impulse_responses` never passes it).

Tests: `direct=True` and `direct=False` warn (pointing to the caller) and
give the closed-form responses, and no warning is emitted without
`direct`. Both new tests fail on main.
@bashtage
bashtage marked this pull request as ready for review November 23, 2026 00:15
@bashtage
bashtage merged commit 295a899 into statsmodels:main Nov 23, 2026
11 of 12 checks passed
@bashtage
bashtage deleted the wip-ss-impulse-integer 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