Skip to content

BUG: Accept a dataset in news for a univariate model with longer exog - #11273

Merged
bashtage merged 2 commits into
statsmodels:mainfrom
bashtage:wip-news-univariate-comparison-array
Nov 27, 2026
Merged

bashtage merged 2 commits into
statsmodels:mainfrom
bashtage:wip-news-univariate-comparison-array

Conversation

@bashtage

Copy link
Copy Markdown
Member

Stacked on #11254.

When the comparison passed to MLEResults.news is a dataset and exog
has more periods than it, _get_previous_updated extends the dataset
with missing values and wraps it in a DataFrame whose columns are
self.model.endog_names. For a univariate model endog_names is a str
such as "y", which pandas rejects, so
SARIMAX(endog[:15], exog=exog[:15], order=(1, 0, 0)).smooth(params) .news(endog, exog=exog[:17], impact_date=16) raised TypeError: Index(...) must be called with a collection of some kind, 'y' was passed, for an ndarray, a list or a Series. Passing the equivalent
updated results object worked.

Changes

  • The columns are np.atleast_1d(self.model.endog_names), so a
    univariate model gets one column named after its endog.
  • A versionchanged note for comparison.

Not changed

  • Multivariate models, comparisons that are results objects, and
    comparisons whose length matches exog.

Tests

  • test_news_univariate_comparison_with_longer_exog, for a 1-d array,
    an (n, 1) column, a list and a Series: for a regression with AR(1)
    errors and fixed parameters, the previous and updated forecasts of the
    impact date and the total impact equal the closed forms
    beta * x[16] + phi**2 * u[14] and beta * x[16] + phi * u[15] with
    u = y - beta * x, and the news equals the news computed from the
    updated results object. All four cases fail on the base with the
    TypeError and pass here. test_mlemodel.py and test_news.py pass on
    the oldest, mid and latest dependency sets.

  • 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 while sweeping input validation, writing the fix and its tests, and checking them (tests failing on main, three NumPy/pandas versions).
    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

Stacked on statsmodels#11254.

When the comparison passed to `MLEResults.news` is a dataset and `exog`
has more periods than it, `_get_previous_updated` extends the dataset
with missing values and wraps it in a DataFrame whose columns are
`self.model.endog_names`. For a univariate model `endog_names` is a str
such as "y", which pandas rejects, so
`SARIMAX(endog[:15], exog=exog[:15], order=(1, 0, 0)).smooth(params)
.news(endog, exog=exog[:17], impact_date=16)` raised `TypeError:
Index(...) must be called with a collection of some kind, 'y' was
passed`, for an ndarray, a list or a Series. Passing the equivalent
updated results object worked.

Changes
- The columns are `np.atleast_1d(self.model.endog_names)`, so a
  univariate model gets one column named after its endog.
- A versionchanged note for `comparison`.

Not changed
- Multivariate models, comparisons that are results objects, and
  comparisons whose length matches `exog`.

Tests
- `test_news_univariate_comparison_with_longer_exog`, for a 1-d array,
  an (n, 1) column, a list and a Series: for a regression with AR(1)
  errors and fixed parameters, the previous and updated forecasts of the
  impact date and the total impact equal the closed forms
  `beta * x[16] + phi**2 * u[14]` and `beta * x[16] + phi * u[15]` with
  `u = y - beta * x`, and the news equals the news computed from the
  updated results object. All four cases fail on the base with the
  TypeError and pass here. `test_mlemodel.py` and `test_news.py` pass on
  the oldest, mid and latest dependency sets.
@bashtage
bashtage marked this pull request as ready for review November 27, 2026 20:06
@bashtage
bashtage merged commit 2539d69 into statsmodels:main Nov 27, 2026
11 of 12 checks passed
@bashtage
bashtage deleted the wip-news-univariate-comparison-array branch November 27, 2026 20:09
bashtage added a commit to bashtage/statsmodels that referenced this pull request Nov 27, 2026
statsmodels#11273 made MLEResults.news accept a comparison dataset shorter than
exog for a univariate model. Add a test for the cases its test does not
cover: a VAR(1) with exog besides the regression with AR(1) errors, the
total impact compared with its closed form, and the news compared with
the news from results for the dataset extended by hand.

Tests
- For a regression with AR(1) errors and a VAR(1) with exog, the total
  impact of observing y_10 on the forecast of y_11 equals the closed form
  (phi (u_10 - phi u_9) and A (y_10 - A y_9 - B x_10)), the columns are
  the endog names, and the news equals the news from results for the
  dataset extended by hand with missing values.
bashtage added a commit to bashtage/statsmodels that referenced this pull request Nov 28, 2026
statsmodels#11273 made MLEResults.news accept a comparison dataset shorter than
exog for a univariate model. Add a test for the cases its test does not
cover: a VAR(1) with exog besides the regression with AR(1) errors, the
total impact compared with its closed form, and the news compared with
the news from results for the dataset extended by hand.

Tests
- For a regression with AR(1) errors and a VAR(1) with exog, the total
  impact of observing y_10 on the forecast of y_11 equals the closed form
  (phi (u_10 - phi u_9) and A (y_10 - A y_9 - B x_10)), the columns are
  the endog names, and the news equals the news from results for the
  dataset extended by hand with missing values.
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