Skip to content

Commit d35eb83

Browse files
mmckyclaude
andauthored
FIX: lecture cleanup batch from the 2026-08 tracker audit (#595)
* FIX: lecture cleanup batch from the 2026-08 tracker audit - 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> * FIX: drop redundant rng re-creation in functions.md 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> * FIX: tidy remaining rng bindings in scipy.md and polars.md 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> * Revert the bench_rng rename in polars.md 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> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 6ee9cdb commit d35eb83

7 files changed

Lines changed: 32 additions & 23 deletions

File tree

lectures/about_py.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ popularity of a single Python deep learning library
139139

140140
```{figure} /_static/lecture_specific/about_py/pytorch_vs_matlab.png
141141
```
142-
Pytorch is just one of several Python libraries for deep learning and AI.
142+
PyTorch is just one of several Python libraries for deep learning and AI.
143143

144144

145145

@@ -349,7 +349,7 @@ We will discuss the details later in the lecture series, where we cover NumPy in
349349
While NumPy is still the king of array processing in Python, there are now
350350
important competitors.
351351

352-
Libraries such as [JAX](https://github.com/jax-ml/jax), [Pytorch](https://pytorch.org/), and [CuPy](https://cupy.dev/) also have
352+
Libraries such as [JAX](https://github.com/jax-ml/jax), [PyTorch](https://pytorch.org/), and [CuPy](https://cupy.dev/) also have
353353
built in array types and array operations that can be very fast and efficient.
354354

355355
In fact these libraries are better at exploiting parallelization and fast hardware, as

lectures/autodiff.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,11 @@ Let's generate some simulated data:
350350
```{code-cell} ipython3
351351
n = 100
352352
key = jax.random.key(1234)
353-
x = jax.random.uniform(key, (n,))
353+
key, x_key, ϵ_key = jax.random.split(key, 3)
354+
x = jax.random.uniform(x_key, (n,))
354355
355356
α, β, σ = 0.5, 1.0, 0.1 # Set the true intercept and slope.
356-
key, subkey = jax.random.split(key)
357-
ϵ = jax.random.normal(subkey, (n,))
357+
ϵ = jax.random.normal(ϵ_key, (n,))
358358
359359
y = α * x + β + σ * ϵ
360360
```

lectures/numpy.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,11 @@ class DiscreteRV:
12521252
def __init__(self, q, seed=None):
12531253
"""
12541254
The argument q is a NumPy array, or array like, nonnegative and sums
1255-
to 1
1255+
to 1.
1256+
1257+
The argument seed sets the seed for the underlying random number
1258+
generator; with the default seed=None, draws are not reproducible
1259+
across runs.
12561260
"""
12571261
self.q = q
12581262
self.Q = cumsum(q)
@@ -1431,7 +1435,7 @@ print(A)
14311435

14321436
**Part 2**: Move on to replicate the result of the following broadcasting operation. Meanwhile, compare the speeds of broadcasting and the `for` loop you implement.
14331437

1434-
For this part of the exercise you can use the `tic`/`toc` functions from the `quantecon` library to time the execution.
1438+
For this part of the exercise you can use the `qe.Timer()` context manager from the `quantecon` library to time the execution.
14351439

14361440
Let's make sure this library is installed.
14371441

lectures/pandas.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ Let's start with Series.
8989
We begin by creating a series of four random observations
9090

9191
```{code-cell} ipython3
92-
s = pd.Series(np.random.randn(4), name='daily returns')
92+
rng = np.random.default_rng()
93+
s = pd.Series(rng.standard_normal(4), name='daily returns')
9394
s
9495
```
9596

lectures/pandas_panel.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ countries and assign it to `realwage`.
7777
The dataset can be accessed with the following link:
7878

7979
```{code-cell} ipython3
80-
url1 = 'https://github.com/QuantEcon/data-lectures/raw/main/lectures/realwage.csv'
80+
url1 = 'https://raw.githubusercontent.com/QuantEcon/data-lectures/main/lectures/realwage.csv'
8181
```
8282

8383
```{code-cell} ipython3
@@ -197,7 +197,7 @@ function.
197197
The dataset can be accessed with the following link:
198198

199199
```{code-cell} ipython3
200-
url2 = 'https://github.com/QuantEcon/data-lectures/raw/main/lectures/countries.csv'
200+
url2 = 'https://raw.githubusercontent.com/QuantEcon/data-lectures/main/lectures/countries.csv'
201201
```
202202

203203
```{code-cell} ipython3
@@ -506,7 +506,7 @@ in Europe by age and sex from [Eurostat](https://ec.europa.eu/eurostat/data/data
506506
The dataset can be accessed with the following link:
507507

508508
```{code-cell} ipython3
509-
url3 = 'https://github.com/QuantEcon/data-lectures/raw/main/lectures/employ.csv'
509+
url3 = 'https://raw.githubusercontent.com/QuantEcon/data-lectures/main/lectures/employ.csv'
510510
```
511511

512512
Reading in the CSV file returns a panel dataset in long format. Use `.pivot_table()` to construct

lectures/polars.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ Let's start with Series.
7878
We begin by creating a series of four random observations
7979

8080
```{code-cell} ipython3
81-
s = pl.Series(name='daily returns', values=np.random.randn(4))
81+
rng = np.random.default_rng()
82+
s = pl.Series(name='daily returns', values=rng.standard_normal(4))
8283
s
8384
```
8485

@@ -114,7 +115,7 @@ For example, to associate ticker symbols with returns:
114115
```{code-cell} ipython3
115116
df = pl.DataFrame({
116117
'company': ['AMZN', 'AAPL', 'MSFT', 'GOOG'],
117-
'daily returns': np.random.randn(4)
118+
'daily returns': rng.standard_normal(4)
118119
})
119120
df
120121
```
@@ -463,13 +464,13 @@ a grouped weighted average.
463464

464465
```{code-cell} ipython3
465466
n = 5_000_000
466-
np.random.seed(42)
467+
rng = np.random.default_rng(42)
467468
468-
groups = np.random.choice(['A', 'B', 'C', 'D'], n)
469-
values = np.random.randn(n)
470-
weights = np.random.rand(n)
471-
extra1 = np.random.randn(n)
472-
extra2 = np.random.randn(n)
469+
groups = rng.choice(['A', 'B', 'C', 'D'], n)
470+
values = rng.standard_normal(n)
471+
weights = rng.random(n)
472+
extra1 = rng.standard_normal(n)
473+
extra2 = rng.standard_normal(n)
473474
474475
big_pd = pd.DataFrame({
475476
'group': groups, 'value': values,
@@ -685,7 +686,7 @@ Calculate percentage changes using Polars expressions:
685686

686687
```{code-cell} ipython3
687688
price_change = ticker.select([
688-
((pl.col(tick).last() / pl.col(tick).first() - 1) * 100)
689+
((pl.col(tick).drop_nulls().last() / pl.col(tick).drop_nulls().first() - 1) * 100)
689690
.alias(tick)
690691
for tick in ticker_list.keys()
691692
]).transpose(

lectures/python_by_example.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,22 @@ Then it's harder for readers to know where `sqrt` came from, should they wish to
173173

174174
### Random Draws
175175

176-
Returning to our program that plots white noise, the remaining three lines
176+
Returning to our program that plots white noise, the remaining four lines
177177
after the import statements are
178178

179179
```{code-cell} ipython
180+
rng = np.random.default_rng()
180181
ϵ_values = rng.standard_normal(100)
181182
plt.plot(ϵ_values)
182183
plt.show()
183184
```
184185

185-
The first line generates 100 (quasi) independent standard normals and stores
186+
The first line creates a random number generator `rng`.
187+
188+
The second line generates 100 (quasi) independent standard normals and stores
186189
them in `ϵ_values`.
187190

188-
The next two lines genererate the plot.
191+
The last two lines generate the plot.
189192

190193
We can and will look at various ways to configure and improve this plot below.
191194

0 commit comments

Comments
 (0)