QuantEcon · GitHub

Commit 1ed02f0

mmckyclaude

and

authored

[inequality] Take writeable copy before rd.shuffle (pandas 3.0) (#776)

pandas 3.0 returns a read-only array from np.asarray() of a Series (Copy-on-Write), so rd.shuffle(y) raised "ValueError: assignment destination is read-only" during the anaconda=2026.06 build. Take a writeable .copy() before the in-place shuffle. See #775. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

  • lectures

Lines changed: 2 additions & 1 deletion

Original file line numberDiff line numberDiff line change

@@ -284,7 +284,8 @@ for var in varlist:

284284

# Repeat the observations according to their weights

285285

counts = list(round(df[df['year'] == year]['weights'] ))

286286

y = df[df['year'] == year][var].repeat(counts)

287-

y = np.asarray(y)

287+

# `.copy()` gives a writeable array (pandas 3.0 returns a read-only one)

288+

y = np.asarray(y).copy()

288289
289290

# Shuffle the sequence to improve the plot

290291

rd.shuffle(y)

Read the original on github.com ↗