Skip to content

TST: Cover NewsResults and the state space news entry points - #11078

Merged
bashtage merged 3 commits into
statsmodels:mainfrom
bashtage:wip-tsa-cov-c11
Nov 25, 2026
Merged

bashtage merged 3 commits into
statsmodels:mainfrom
bashtage:wip-tsa-cov-c11

Conversation

@bashtage

Copy link
Copy Markdown
Member

Only news.py (docstrings) and test_news.py change. #11054, #11057, #11058, #11029 and #11025 change the news entry points in kalman_smoother.py and mlemodel.py and their test files; this PR has no file in common with them and merges cleanly in any order.

TST: Cover the tables and summaries of NewsResults

Add tests of the paths of statespace/news.py that the TSA test suite did
not reach, each checked against an independent value:

  • closed forms for an AR(1) model with a revision and an update: the
    weights, revisions, news and impacts of revision_details_by_impact
    (with all revisions detailed) and details_by_impact, and the estimates
    of the impacts table; with two updates, the details table of each
    update date;
  • the details tables summed over the revisions or updates give the
    revision and update impacts, and these add up to the change in the
    estimates, with detailed and with grouped revisions;
  • impacted_variable (str, list, array and slice, given to news or set on
    the results) and tolerance (set on the results) select the rows of
    every details table and of the impacts table;
  • summary_impacts, summary_details, summary_news and summary_revisions:
    every cell of the tables against the DataFrames they show (the AR(1)
    closed forms for the univariate details), with and without sparsifying,
    with each groupby (and its underscore spelling), the impact and update
    date and variable selections, multiple tables, the univariate defaults,
    show_revisions_columns, the weights shown as 1.0 and 0, equal values of
    different variables (not blanked), and the errors for an invalid
    groupby;
  • summary: the header (samples, revisions, new datapoints, included
    states) and its tables against the individual summary methods with
    every argument (including the revision date and revised variable of
    the details of revisions), for univariate and multivariate models;
  • state_index: in a VAR(1) the impacts of the news and the detailed
    impacts of the revisions through the first state are those of the
    first variable;
  • get_details and get_impacts with each include flag (summing to the
    matching impacts), and get_impacts with a groupby of the updated
    variables.

Two bugs of NewsResults, not fixed here, shape the tests: the univariate
summaries are tested with a one-letter series name (k_endog is the length
of the name of the series of a univariate model), and
test_get_impacts_groupby ignores the two FutureWarnings that pandas < 3
raises in get_impacts with a groupby (stack without future_stack).

Coverage of news.py by the TSA tests goes from 85.6% to 97.0% of the
lines and from 63.9% to 98.3% of the branches.

DOC: Correct the docstrings of NewsResults

Fix the docstrings of statespace/news.py where they disagree with the
code. No code changes.

  • get_impacts: groupby groups the updated (or revised) variables
    separately for each update date, for example with a dict or a function
    of the variable names; it is not applied to the combined details table
    and cannot group the update dates, which the docstring gave as its
    example (that raises a KeyError). The index of the result has the
    levels update date and updated variable (or the groups).

  • get_details also renames the index levels of the revision details, and
    both get_details and get_impacts return an empty table if both include
    flags are False.

  • summary_news has a news column; the columns of data_updates,
    data_revisions, details_by_impact and revision_details_by_impact and
    the index levels of details_by_update and revision_details_by_update
    are listed in their actual order; the details tables and impacts only
    include the rows above tolerance and of the selected
    impacted_variable.

  • impacted_variable and tolerance (settable properties) get docstrings.

  • summary_details: updated_variable are the variables that generated
    the news, not those affected by it, and with source="revisions",
    update_date, updated_variable and groupby refer to the revision
    dates and revised variables.

  • summary: the news table is listed, the revisions tables are shown only
    with include_revisions_tables=True (default False) and only if the
    data were revised, and revision_date and revised_variable apply to
    the details tables of revisions.

  • NewsResults takes the results of SmootherResults.news (there is no
    KalmanSmoother.news).

  • 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: auditing the coverage gaps and the docstrings of NewsResults against the code, writing the tests (checked against closed forms of an AR(1) model and identities between the tables and the DataFrames they show) and the docstring fixes, and checking them (coverage before and after, mutation check of the newly covered lines).
    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

Add tests of the paths of statespace/news.py that the TSA test suite did
not reach, each checked against an independent value:

- closed forms for an AR(1) model with a revision and an update: the
  weights, revisions, news and impacts of revision_details_by_impact
  (with all revisions detailed) and details_by_impact, and the estimates
  of the impacts table; with two updates, the details table of each
  update date;
- the details tables summed over the revisions or updates give the
  revision and update impacts, and these add up to the change in the
  estimates, with detailed and with grouped revisions;
- impacted_variable (str, list, array and slice, given to news or set on
  the results) and tolerance (set on the results) select the rows of
  every details table and of the impacts table;
- summary_impacts, summary_details, summary_news and summary_revisions:
  every cell of the tables against the DataFrames they show (the AR(1)
  closed forms for the univariate details), with and without sparsifying,
  with each groupby (and its underscore spelling), the impact and update
  date and variable selections, multiple tables, the univariate defaults,
  show_revisions_columns, the weights shown as 1.0 and 0, equal values of
  different variables (not blanked), and the errors for an invalid
  groupby;
- summary: the header (samples, revisions, new datapoints, included
  states) and its tables against the individual summary methods with
  every argument (including the revision date and revised variable of
  the details of revisions), for univariate and multivariate models;
- state_index: in a VAR(1) the impacts of the news and the detailed
  impacts of the revisions through the first state are those of the
  first variable;
- get_details and get_impacts with each include flag (summing to the
  matching impacts), and get_impacts with a groupby of the updated
  variables.

Two bugs of NewsResults, not fixed here, shape the tests: the univariate
summaries are tested with a one-letter series name (k_endog is the length
of the name of the series of a univariate model), and
test_get_impacts_groupby ignores the two FutureWarnings that pandas < 3
raises in get_impacts with a groupby (stack without future_stack).

Coverage of news.py by the TSA tests goes from 85.6% to 97.0% of the
lines and from 63.9% to 98.3% of the branches.
Fix the docstrings of statespace/news.py where they disagree with the
code. No code changes.

- get_impacts: `groupby` groups the updated (or revised) variables
  separately for each update date, for example with a dict or a function
  of the variable names; it is not applied to the combined details table
  and cannot group the update dates, which the docstring gave as its
  example (that raises a KeyError). The index of the result has the
  levels `update date` and `updated variable` (or the groups).
- get_details also renames the index levels of the revision details, and
  both get_details and get_impacts return an empty table if both include
  flags are False.
- summary_news has a `news` column; the columns of data_updates,
  data_revisions, details_by_impact and revision_details_by_impact and
  the index levels of details_by_update and revision_details_by_update
  are listed in their actual order; the details tables and impacts only
  include the rows above `tolerance` and of the selected
  `impacted_variable`.
- impacted_variable and tolerance (settable properties) get docstrings.
- summary_details: `updated_variable` are the variables that generated
  the news, not those affected by it, and with `source="revisions"`,
  `update_date`, `updated_variable` and `groupby` refer to the revision
  dates and revised variables.
- summary: the news table is listed, the revisions tables are shown only
  with `include_revisions_tables=True` (default False) and only if the
  data were revised, and `revision_date` and `revised_variable` apply to
  the details tables of revisions.
- NewsResults takes the results of SmootherResults.news (there is no
  KalmanSmoother.news).
@bashtage

bashtage commented Nov 23, 2026 •

Copy link
Copy Markdown
Member Author

@bashtage
bashtage marked this pull request as ready for review November 25, 2026 08:42
@bashtage
bashtage merged commit 6fe856d into statsmodels:main Nov 25, 2026
11 of 12 checks passed
bashtage added a commit that referenced this pull request Nov 25, 2026
… model

NewsResults set k_endog = len(self.endog_names), and endog_names of a
univariate model is the name of the series (a str), so k_endog was the
length of the name. The documented univariate defaults applied only to
series with a one-letter name. For a series named "infl" (k_endog = 4),
summary showed no details tables by default, include_details_tables=True
gave one details table per update date, summary_details with
multiple_tables=True kept the variable columns, and
summary(details_groupby="impact date") raised a KeyError.

Where they applied, the defaults selected the rows of the tables by the
name of the variable, so for one-letter names summary raised a KeyError
when there were no new observations or no impacts above the tolerance (an
empty table), and with include_revisions_tables=True when all revisions
were grouped (the default revisions_details_start=False); with some
revisions grouped, the "all prior revisions" rows were silently dropped
from the details of the revisions. Fixing k_endog alone would have made
these errors happen for every univariate model.

Changes
- k_endog is the number of variables of the model.
- The single variable of a univariate model no longer selects the rows of
  the tables: summary_impacts used it only to select the rows (a no-op
  otherwise), and summary_details treats it as selected, so that it is
  moved to the title of multiple tables.
- summary leaves out a single details table without rows, as it does for
  multiple tables, so the summary of a univariate model without news (or
  without impacts above the tolerance) gains no empty table.
- versionchanged in the docstring of summary.

Results change for valid input of univariate models whose series name is
longer than one character: summary shows the details tables by default,
as documented, and a single details table for any details_groupby;
summary_details(multiple_tables=True) shows the variable in the title;
k_endog is 1. For one-letter names, the details of the revisions include
the grouped revisions.

Not changed
- Multivariate models, and the tables of univariate models apart from the
  above.

Tests
- For a series named "infl" and "y", k_endog is 1, summary shows a single
  details table of the news and of the revisions by default for each
  grouping (also a table with a single row), and multiple tables show the
  variable in the title.
- For both names, with revisions only (all grouped), with some revisions
  grouped, and with no impact above the tolerance, summary shows the
  expected tables (no empty details tables), and the details of the
  revisions include the grouped revisions and sum to the impacts of the
  revisions. These cases fail on the base for "y" (and with k_endog fixed
  alone, also for "infl").
- A multivariate model with news for a single variable keeps the updated
  variable in a column of multiple tables unless it is selected.
- The univariate tests of #11078 use the name of the series ("infl")
  instead of "y", which they used because of this bug, and
  test_summary_univariate runs with both names.
@bashtage
bashtage deleted the wip-tsa-cov-c11 branch November 25, 2026 16:51
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