FIX: lecture cleanup batch from the 2026-08 tracker audit - #595
Conversation
- polars: guard Exercise 1 first/last with drop_nulls (#589) - polars, pandas: migrate the remaining legacy np.random.* call sites to the Generator API (#552) - pandas_panel: use direct raw.githubusercontent.com data URLs (#580) - python_by_example: include the rng line in the white-noise snippet and correct the line count (#552) - functions, scipy: define rng in the cells that use it (#552) - numpy: document DiscreteRV's seed parameter (#552) and reference qe.Timer() instead of the retired tic/toc wording (#594) - about_py: standardize on PyTorch (#552) - autodiff: split the PRNG key once into three single-use keys (#529) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR applies a batch of small, audit-driven fixes across multiple lecture sources so that all translated editions pick them up in the next sync.
Changes:
- Fix RNG scoping / modernize random draws in several lectures (NumPy Generator API usage and per-cell
rngdefinitions where needed). - Improve correctness/robustness in examples (Polars
drop_nulls()guard forfirst()/last(), JAX single-use PRNG key splitting). - Clean up lecture text and links (raw GitHub CSV URLs, docstring/text consistency, PyTorch capitalization).
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| lectures/scipy.md | Defines rng locally in the linregress example cell to avoid hidden dependencies. |
| lectures/python_by_example.md | Aligns prose and snippet for white-noise example (adds rng line; fixes typo/count). |
| lectures/polars.md | Migrates random draws to Generator API; seeds benchmark via default_rng(42); guards first/last with drop_nulls(). |
| lectures/pandas.md | Keeps the mirrored Series example consistent with polars.md by using Generator API. |
| lectures/pandas_panel.md | Switches dataset URLs to direct raw.githubusercontent.com links (no redirect). |
| lectures/numpy.md | Documents seed in DiscreteRV.__init__ docstring; updates exercise text to reference qe.Timer() instead of tic/toc. |
| lectures/functions.md | Defines rng in each relevant code cell so running cells in isolation won’t raise NameError. |
| lectures/autodiff.md | Fixes JAX key reuse by splitting once into single-use subkeys for independent draws. |
| lectures/about_py.md | Standardizes “PyTorch” capitalization in prose and links. |
|
@Chihiro2000GitHub would you have time to cast an eye over these changes. Many of them are |
|
Thanks @mmcky! I've had a quick look through the changes. I'll do a proper review starting this weekend and get back to you with any comments 😊 |
The three added `rng = np.random.default_rng()` lines re-bound a generator that is already created at the top of the "Random Draws" section and carried forward through notebook state, so they changed nothing at execution time while adding boilerplate to cells whose subject is function structure. Reverts functions.md to match main. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Reviewed the To answer the question that prompted the look: the The problem was that the three added The change was also inconsistent about it: the Given the lecture establishes |
| to 1 | ||
| to 1. | ||
|
|
||
| The argument seed sets the seed for the underlying random number |
There was a problem hiding this comment.
@jstac what is your view on docstrings in lectures. Should they fully document a function interface (like in a library) or be a concise one sentence description?
scipy.md: drop the redundant rng re-creation before the linregress example, which re-bound a generator already created earlier in the lecture. Reverts scipy.md to match main. polars.md: rename the seeded benchmark generator to bench_rng so it no longer shadows the unseeded rng created in the Series section with one carrying different semantics. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Followed up on the remaining
The other RNG changes all look right and are unchanged:
Also confirmed there are no legacy The working rule I applied, if it is useful as a convention: re-create |
Reusing the rng name for the seeded benchmark generator is fine: the rename was a readability preference with no effect on output, and nothing downstream of the benchmark cell reads rng. The seed is unchanged, so the benchmark data stays reproducible. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Correction to my previous comment: the Reusing the name is fine here. The rename was a readability preference rather than a fix, it had no effect on output, and nothing downstream of the benchmark cell reads The |
|
@Chihiro2000GitHub I had a closer look and I actually removed a number of the @jstac this is good to go -- bar the final call re: |
One batch of small, independently verified fixes from the 2026-08 tracker audit. They are grouped into a single PR because every item touches lecture source, so batching means the
.fa/.fr/.zh-cneditions pick everything up in one translation sync instead of five.Closes #589, closes #580, closes #552, closes #529, closes #594.
Changes
polars.mdfirst()/last()withdrop_nulls(), matching Exercise 2 — without it, tickers on different trading calendars produce nullpct_changevalues that flow silently into the bar chartpandas_panel.mdgithub.com/QuantEcon/data-lectures/raw/main/...URLs now point directly atraw.githubusercontent.com, avoiding the 302 redirectpython_by_example.mdrng = np.random.default_rng()line and the prose counts four lines, not three (also fixes a "genererate" typo)functions.mdgenerate_datacells definernglocally, so running a cell in isolation no longer raisesNameErrorscipy.mdlinregressexample definesrngin its own cell (matching the pattern already used at the Monte Carlo example later in the lecture)numpy.mdDiscreteRV.__init__docstring now documents theseedparameter and the non-reproducibility of theseed=Nonedefaultabout_py.mdpolars.md,pandas.mdnp.random.*call sites inpolars.mdmigrated to the Generator API; the mirrored Series cell inpandas.md(np.random.randn(4), the one site the audit had not flagged) is migrated too so the twin lectures stay consistentautodiff.mdkeywithuniformand then re-splitting it (correlated-draws risk); uses the fix suggested in the issue, withϵ_keynamed to match the lecture's unicode conventionnumpy.mdqe.Timer()context manager instead of the retiredtic/tocwording, matching the solution codeNotes for review
Random streams change in the edited cells: the polars/pandas Series and DataFrame demo cells now draw from a fresh
Generator, and the polars benchmark block seeds vianp.random.default_rng(42)instead ofnp.random.seed(42). Displayed numbers in the published output will differ from the current build, but nothing pedagogical depends on the specific draws. This is the same trade accepted throughout the series-wide Generator migration (#538–#549).The
rng-scoping fixes follow the convention already used by the migrated lectures (numba.md,numpy.mddefinerngin each cell/section that uses it) rather than introducing a shared top-of-lecture definition.🤖 Generated with Claude Code