Skip to content

inflation_history, fitting_distributions: state what pandas now warns about - #876

Merged
mmcky merged 2 commits into
mainfrom
silence-pandas-deprecations
Nov 22, 2026
Merged

mmcky merged 2 commits into
mainfrom
silence-pandas-deprecations

Conversation

@mmcky

@mmcky mmcky commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What

Two cells print a pandas warning into their output. This states what pandas asks for, keeping the results the same:

Lecture Before After The warning
inflation_history df_list.append(pd.concat(sheet_list, axis=1)) df_list.append(pd.concat(sheet_list, axis=1, sort=True)) Pandas4Warning: "Sorting by default when concatenating all DatetimeIndex is deprecated. In the future, pandas will respect the default of sort=False." sort=True keeps today's sorted result.
fitting_distributions monthly = times.dt.to_period('M').value_counts().sort_index() monthly = quakes.set_index(times).resample('MS').size() UserWarning: "Converting to PeriodArray/Index representation will drop timezone information." times is in UTC, and a period has no time zone. resample counts the events in each calendar month directly, with no time-zone step and no warning, and counts a month with no earthquakes as 0, where value_counts leaves it out; the comparison of the mean with the variance that follows needs those zeros. Every one of the 300 months has an event, so the printed mean and variance are unchanged.

Both were found by the environment scan of 2026-11-19 and are in intro's own builds. This is part of reporting lecture fixes upstream to each lecture's source of truth (QuantEcon/project-monorepo#77).

Validation

Done on 2026-11-22, a full validation; the evidence is in the comments below. The fitting_distributions line changed after that validation, from tz_localize(None) and to_period('M') to resample('MS') (6280118); its own validation follows in a comment. Fresh builds with no cache of this pull request and of main, every notebook executed, both green. In the two lectures both warnings are gone, and every other output and figure is identical.

This changes lecture content, so it needs a person's review.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WT8bMacV9Lmy1VLUc6XJoL

… about

Two cells printed a pandas warning into their output:

- inflation_history: pd.concat of the sheets, which all have a
  DatetimeIndex, sorts the joined index by default, which pandas 3
  deprecates (Pandas4Warning: "Sorting by default when concatenating all
  DatetimeIndex is deprecated"). `sort=True` keeps today's sorted result.
- fitting_distributions: `times` is in UTC, and converting it to monthly
  periods drops the time zone, with a UserWarning. Dropping it first with
  `tz_localize(None)` gives the same months, without the warning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WT8bMacV9Lmy1VLUc6XJoL
@netlify

netlify Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for taupe-gaufre-c4e660 ready!

Name Link
🔨 Latest commit 6280118
🔍 Latest deploy log https://app.netlify.com/projects/taupe-gaufre-c4e660/deploys/6b03681a511c5ba9ba8b0423
😎 Deploy Preview https://deploy-preview-876--taupe-gaufre-c4e660.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

@github-actions
github-actions Bot temporarily deployed to pull request November 22, 2026 10:28 Inactive
@github-actions
github-actions Bot temporarily deployed to pull request November 22, 2026 10:29 Inactive
@mmcky

mmcky commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Validation: a full validation

Two fresh builds with no cache, each executing all 54 notebooks, -W --keep-going, both green:

Build Run
main at 8db8a99, this branch's base, 2026-11-22 44991424113
this pull request at acff0f1, 2026-11-22 45013689650

This pull request's first fresh build, 45012267153, failed on eight pages, all with HTTP 429 (Too Many Requests) while downloading data from QuantEcon/data-lectures. That day thirteen validation builds started at once, and GitHub rate-limited the downloads. The run above is the same build again, later.

The two changed lectures. In each, the only difference is the changed line itself and the warning, which is gone. Every other output is identical, and so is every figure, byte for byte.

Lecture main this pull request
inflation_history Pandas4Warning: "Sorting by default when concatenating all DatetimeIndex is deprecated…" none
fitting_distributions UserWarning: "Converting to PeriodArray/Index representation will drop timezone information." none

Build logs. The same warning lines on both sides, and no Sphinx warning on either.

The rest of the HTML. 20 of 66 pages differ in all. Besides the two above, there are three kinds of difference, as between any two builds:

  • Output noise: random draws, memory addresses and timings, on 7 pages.
  • Figure file names: on 15 pages, because a figure's file is named by its content, and an unseeded figure that is drawn again gets a new name.
  • The status page: build times.

The warnings in the other pages' outputs are the same on both sides.

@mmcky
mmcky marked this pull request as ready for review November 22, 2026 11:02
Copilot AI adaptive review requested due to automatic review settings November 22, 2026 11:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human review is needed to confirm that the executable lecture changes preserve the intended pandas-version-specific warning behavior and instructional outputs across regenerated notebooks and external data.

No open issues 🎉

What changed in this PR

This PR updates two executable lecture examples to make pandas behavior explicit, removing deprecation and timezone-conversion warnings while preserving existing results.

Changes:

  • Sets sort=True when concatenating time-indexed data in inflation_history.
  • Removes timezone information before converting timestamps to monthly periods in fitting_distributions.
  • No actionable code issues identified.
File Description
lectures/​inflation_history.md Makes the concatenation sort behavior explicit for pandas compatibility.
lectures/​fitting_distributions.md Removes UTC timezone information before monthly period conversion.

Review effort: Lite (adaptive)

The previous commit removed the time zone with `tz_localize(None)`
before `to_period('M')`, because pandas warns that converting UTC times
to periods drops the zone. `quakes.set_index(times).resample('MS').size()`
counts the events in each calendar month directly: it needs no time-zone
step and gives no warning. It also counts a month with no earthquakes as
0, where `value_counts` leaves that month out, and the comparison of the
mean with the variance that follows needs those zeros.

On japan_earthquakes.csv every one of the 300 months has an event, so
the printed mean and variance are unchanged (11.857 and 1148.98).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WT8bMacV9Lmy1VLUc6XJoL
@github-actions
github-actions Bot temporarily deployed to pull request November 22, 2026 22:16 Inactive
@mmcky

mmcky commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Validation of 6280118: a full validation

6280118 changes one line in fitting_distributions, from times.dt.tz_localize(None).dt.to_period('M').value_counts().sort_index() to quakes.set_index(times).resample('MS').size(). This validates the pull request at that head, with a fresh build that has no cache and executes all 54 notebooks with -W --keep-going. It is compared with the same build of main used above, made the same day at this branch's base. Both builds are green:

Build Run
main at 8db8a99, this branch's base, 2026-11-22 05:54 UTC 44991424113
this pull request at 6280118, 2026-11-22 22:09 UTC 45076130455

The two changed lectures. Both warnings are gone. fitting_distributions prints the same mean and variance as main, (11.856666666666667, 1148.9793868450386). Its only other difference from main is the changed code line itself. inflation_history is as in the first validation. Every figure on both pages is identical to main's.

Build logs. The same warning lines on both sides, and no Sphinx warning on either.

The rest of the HTML. 20 of 66 pages differ in all: the same 20 as in the first validation, for the same reasons (random draws, memory addresses and timings, figure file names, and the status page's build times). Every other page's output warnings are the same on both sides. Compared with this pull request's build at acff0f1 (45013689650), 19 pages differ: fitting_distributions in its changed code line only, and the same noise pages.

@mmcky
mmcky merged commit 9d33323 into main Nov 22, 2026
9 checks passed
@mmcky
mmcky deleted the silence-pandas-deprecations branch November 22, 2026 23:04
@mmcky

mmcky commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

✅ Translation sync completed (zh-cn)

Target repo: QuantEcon/lecture-intro.zh-cn
Translation PR: QuantEcon/lecture-intro.zh-cn#328
Files synced (2):

  • lectures/fitting_distributions.md
  • lectures/inflation_history.md

This branch was successfully deployed

1 active deployment
pull request — 62801183 Deployed Nov 22, 2026 by github-actions[bot]
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.

2 participants