Skip to content

Commit 7c6d892

Browse files
mmckyclaude
andcommitted
[inequality] Take writeable copy before rd.shuffle (pandas 3.0)
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 parent c1e7c63 commit 7c6d892

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

lectures/inequality.md

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)

0 commit comments

Comments
 (0)