Skip to content

BUG: Give NewsResults.get_impacts the same rows on every pandas version - #11081

Draft
bashtage wants to merge 3 commits into
statsmodels:mainfrom
bashtage:wip-news-get-impacts-stack
Draft

bashtage wants to merge 3 commits into
statsmodels:mainfrom
bashtage:wip-news-get-impacts-stack

Conversation

@bashtage

@bashtage bashtage commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

#11078, which this PR was stacked on, is merged. It removes the two filterwarnings marks that #11078 put on test_get_impacts_groupby. The other C11 follow-up PRs (the NewsResults table fixes and the get_impacts fix) also append to test_news.py: keep both appended blocks. No conflict with #11054, #11057, #11058 or #11029.

BUG: Give NewsResults.get_impacts the same rows on every pandas version

get_impacts(groupby=...) sums the impacts of the groups of updated
variables for each update date and stacks the update dates back into the
rows with .stack("update date"). On pandas 2.1 to 2.3 this raised two
FutureWarnings (the previous implementation of stack, and Index.insert
with object dtype). The previous implementation drops the rows that are
all NaN, which pandas 3 keeps, so on pandas 3 a group without impacts on
an update date had a row of NaN: for example, with a revision of unemp in
2009Q2 and new data for realgdp in 2009Q3 only, grouping each variable on
its own gave four rows instead of two.

Changes

  • The update dates are stacked with FUTURE_STACK, as elsewhere in the
    module, and the all-NaN rows are dropped explicitly, so the rows are
    those of pandas < 3 on every version.

Results change on pandas 3 for groups without impacts on an update date:
their rows of NaN are gone. On pandas 2.1 to 2.3, a grouped table without
impacts (for example the impacts of news when there were only revisions)
is empty instead of raising "ValueError: Must pass non-zero number of
levels/codes". pandas < 2.1 is unchanged (FUTURE_STACK is empty there, and
the old stack already drops the all-NaN rows).

Not changed

  • get_impacts without a groupby, and every other row and value: checked
    against pandas 2.3.3 with the base for grouped tables of revisions and
    news, with a function, a dict and a level as groupby, with a date and an
    integer index.

Tests

  • With a revision of one variable and new data for the other, for each
    combination of include_revisions and include_updates, the grouped rows
    are the update dates and groups with impacts, with the impacts of the
    single variable of each group. The case with both fails on the base on
    pandas 3, and every case warns on pandas 2.3.

  • test_get_impacts_groupby no longer ignores the FutureWarnings.

  • 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

@bashtage

Copy link
Copy Markdown
Member Author

Merge order. These open PRs build on this one (their branches contain its commits), so please merge this PR first:

Once this PR is merged, their diffs shrink to their own changes. Each of them also says "Stacked on #..." at the top of its description.

Merge-order note generated with Claude Code (updated 2026-11-25).

@bashtage
bashtage force-pushed the wip-news-get-impacts-stack branch 2 times, most recently from 3eaf464 to 7b88cbe Compare November 27, 2026 00:31
get_impacts(groupby=...) sums the impacts of the groups of updated
variables for each update date and stacks the update dates back into the
rows with .stack("update date"). On pandas 2.1 to 2.3 this raised two
FutureWarnings (the previous implementation of stack, and Index.insert
with object dtype). The previous implementation drops the rows that are
all NaN, which pandas 3 keeps, so on pandas 3 a group without impacts on
an update date had a row of NaN: for example, with a revision of unemp in
2009Q2 and new data for realgdp in 2009Q3 only, grouping each variable on
its own gave four rows instead of two.

Changes
- The update dates are stacked with FUTURE_STACK, as elsewhere in the
  module, and the all-NaN rows are dropped explicitly, so the rows are
  those of pandas < 3 on every version.

Results change on pandas 3 for groups without impacts on an update date:
their rows of NaN are gone. On pandas 2.1 to 2.3, a grouped table without
impacts (for example the impacts of news when there were only revisions)
is empty instead of raising "ValueError: Must pass non-zero number of
levels/codes". pandas < 2.1 is unchanged (FUTURE_STACK is empty there, and
the old stack already drops the all-NaN rows).

Not changed
- get_impacts without a groupby, and every other row and value: checked
  against pandas 2.3.3 with the base for grouped tables of revisions and
  news, with a function, a dict and a level as groupby, with a date and an
  integer index.

Tests
- With a revision of one variable and new data for the other, for each
  combination of include_revisions and include_updates, the grouped rows
  are the update dates and groups with impacts, with the impacts of the
  single variable of each group. The case with both fails on the base on
  pandas 3, and every case warns on pandas 2.3.
- test_get_impacts_groupby no longer ignores the FutureWarnings.
…ndas < 2

With include_revisions=False and include_updates=False the impacts table
is empty, and with groupby, get_impacts raised "ValueError: Must pass
non-zero number of levels/codes" on pandas 1.5.3 (stack of the empty
table; the Azure minimum-versions job, build 10641,
test_get_impacts_groupby_rows[False-False]). An empty table has nothing to
group, so it is returned as it is: the same empty table, with the index
levels "update date" and "updated variable", that pandas 2 and later give.
@bashtage
bashtage force-pushed the wip-news-get-impacts-stack branch from 7b88cbe to d21db4c Compare November 28, 2026 21:36
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