Repository navigation
BUG: Accept numpy integer impulses and deprecate direct - #11039
Merged
Merged
Conversation
…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
marked this pull request as ready for review
November 23, 2026 00:15
This was referenced Nov 23, 2026
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 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_responsesdocstring: keep itsimpulsewording and its "direct ... Not used." text, plus this PR'sversionchangedanddeprecatedblocks.BUG: Accept NumPy integers as the impulse of state space impulse responses
KalmanFilter.impulse_responsesrecognized an index only withtype(impulse) is int, so a NumPy integer (for example an element ofnp.arangeor an index found withnp.argmax) was treated as animpulse vector and raised "Invalid impulse vector. Must be shaped
(k_posdef,)".
MLEModel.impulse_responsesandMLEResults.impulse_responsespassimpulsethrough, so they raisedtoo.
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.versionchangednote in thedocstring.
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 andout-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
directwas 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:
directdefaults to None, and giving it (True or False) emitsa 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 itis not given (
MLEModel.impulse_responsesnever passes it).Tests:
direct=Trueanddirect=Falsewarn (pointing to the caller) andgive the closed-form responses, and no warning is emitted without
direct. Both 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