From 7c6d89215b9ca2cbdabaa874d5dd4e8e02fe092b Mon Sep 17 00:00:00 2001 From: Matt McKay Date: Fri, 26 Jun 2026 17:28:39 +1000 Subject: [PATCH] [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 --- lectures/inequality.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lectures/inequality.md b/lectures/inequality.md index 7a8475fa..1f56e759 100644 --- a/lectures/inequality.md +++ b/lectures/inequality.md @@ -284,7 +284,8 @@ for var in varlist: # Repeat the observations according to their weights counts = list(round(df[df['year'] == year]['weights'] )) y = df[df['year'] == year][var].repeat(counts) - y = np.asarray(y) + # `.copy()` gives a writeable array (pandas 3.0 returns a read-only one) + y = np.asarray(y).copy() # Shuffle the sequence to improve the plot rd.shuffle(y)