You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Follow-ups from np.random → Generator API migration (rng scoping & docs) #552
A few code-quality follow-ups noticed across the recent np.random → numpy.random.Generator migration PRs (#538, #541, #544, #545, #547, #548, #549) — surfaced by Copilot during the corresponding translation-sync reviews in the Farsi target repo. Each is a small fix; grouping in one issue for convenience.
1. python_by_example.md — stale "three lines" wording
In the Random Draws section, the narrative says:
Returning to our program that plots white noise, the remaining three lines after the import statements are
But the snippet now has four lines (rng = np.random.default_rng() was added). Either update the count or include rng = ... in the snippet so the description matches.
2. functions.md — rng referenced in cells where it isn't defined
In Applications → Random sampling, several code cells call rng.standard_normal() / rng.uniform() but don't define rng in the same cell. If the reader runs the cell in isolation (or restarts the kernel), they get NameError: rng is not defined.
Suggested fix: either add rng = np.random.default_rng() to each affected cell, move the RNG setup to the shared imports cell at the top, or pass an RNG into generate_data() to avoid hidden cell-order dependencies.
3. scipy.md — same rng-scoping issue
The linregress example uses x = rng.standard_normal(200) / y = ... rng.standard_normal(200) without defining rng in the same cell/section. Same fix as above (define locally, or document the dependency).
DiscreteRV.__init__ now accepts a seed parameter and initializes self.rng:
def__init__(self, q, seed=None):
\"\"\"TheargumentqisaNumPyarray, orarraylike, nonnegativeandsumsto1
\"\"\"
The docstring only mentions q. Worth documenting what seed controls (and noting that seed=None yields non-reproducible draws).
5. (Bonus) about_py.md — inconsistent "Pytorch" vs "PyTorch"
The file uses both "PyTorch" and "Pytorch" in different paragraphs (and the line Pytorch is just one of several Python libraries for deep learning and AI. near line 142). Standardize on "PyTorch" everywhere.
6. polars.md — legacy np.random.* API (added 2026-08-04)
The Polars lecture (#408, merged 2026-07-30) introduced eight call sites using the legacy API — np.random.seed / np.random.randn / np.random.choice / np.random.rand (lines 81, 117, 466, 468–472) — the exact pattern the series-wide Generator migration above removed. Flagged as Finding 3 in the #408 review but never filed as an issue; tracked here so a single cleanup PR covers all six items.
Happy to send PRs for any/all of these — flagging here first so the team can decide scope/priority.
Cross-confirming from the zh-cn target repo: the same translation-sync PRs were just reviewed in lecture-python-programming.zh-cn and Copilot independently flagged the same items in the corresponding files — items 2 (functions.md rng scoping), 3 (scipy.md rng scoping), and 4 (DiscreteRV missing seed docstring) all reappeared during the zh-cn reviews. Item 1 (the "three lines" wording in python_by_example.md) was also flagged in the zh-cn equivalent.
This independent reproduction from a second target repo suggests these are real upstream issues worth addressing, not language-specific translator artifacts.
Activity
mmcky commentedon May 14, 2026
Cross-confirming from the zh-cn target repo: the same translation-sync PRs were just reviewed in
lecture-python-programming.zh-cnand Copilot independently flagged the same items in the corresponding files — items 2 (functions.md rng scoping), 3 (scipy.md rng scoping), and 4 (DiscreteRV missingseeddocstring) all reappeared during the zh-cn reviews. Item 1 (the "three lines" wording inpython_by_example.md) was also flagged in the zh-cn equivalent.This independent reproduction from a second target repo suggests these are real upstream issues worth addressing, not language-specific translator artifacts.
FIX: lecture cleanup batch from the 2026-08 tracker audit (#595)