Skip to content

FIX: take writeable copy before rd.shuffle in inequality (pandas 3.0) - #224

Merged
mmcky merged 1 commit into
mainfrom
fix/inequality-readonly-array
Jul 16, 2026
Merged

mmcky merged 1 commit into
mainfrom
fix/inequality-readonly-array

Conversation

@mmcky

@mmcky mmcky commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

main is currently red: the cache.yml "Build Cache" run fails with build finished with problems, 6 warnings after the anaconda 2026.06 bump (#221) landed. This ports the upstream fix.

Root cause

anaconda 2026.06 brings pandas 3.0, where Copy-on-Write makes np.asarray() of a Series return a non-writeable array. The in-place shuffle in inequality.md then raises:

Cell In[7], line 25
---> 25  rd.shuffle(y)
ValueError: assignment destination is read-only

Under jb build -W that fails the build, so the job never reaches its artifact upload step. The four undefined label warnings in the log (lorenz_gini, lorenz_gini2, gini_histogram, gini_usa1) are downstream fallout from cells that never ran, not separate problems — 6 warnings total, all from this one lecture.

Why the dependabot PR checks did not catch this

The seven dependabot PRs merged today all passed, but none of them exercised this path. ci.yml and ci-cn.yml restore the existing build-cache artifact, and because no lecture content changed, the notebooks were never re-executed under the new anaconda. Only a from-scratch cache.yml build (no cache, -W) runs them. This was found by dispatching exactly such a build after merging — the same way upstream found it.

Upstream alignment

Ports the fix from QuantEcon/lecture-python-intro#776, which is a two-line change; this is the same two lines with the comment translated. Upstream tracked the full anaconda 2026.06 fallout in their issue #775, which identified three broken notebooks from two root causes.

Lecture Upstream root cause This repo
inequality.md pandas 3.0 read-only array Affected — fixed here
input_output.md quantecon_book_networks imports removed pkg_resources Not affected
networks.md same as input_output.md Not affected

The latter two do not affect us: both lectures install the package at build time with !pip install quantecon_book_networks rather than pinning it, so they pick up the fixed release. The package bug (QuantEcon/quantecon-book-networks#21) is now closed. Confirmed empirically — the failing build logs no warnings at all for input_output or networks.

Verification

Reproducing a read-only array locally raises the identical ValueError: assignment destination is read-only, and .copy() resolves it. Note the local conda env has pandas 2.3.3, so the pandas 3.0 behaviour itself was simulated by marking an array non-writeable rather than reproduced end-to-end; the authoritative check is the cache.yml run after merge.

Follow-up

After merge, cache.yml should be dispatched to confirm the build goes green and to mint a build-cache artifact built against anaconda 2026.06 / quantecon-book-theme 0.21.0. The current artifact predates those bumps.

🤖 Generated with Claude Code

Merging the anaconda 2026.06 bump (#221) brought pandas 3.0, which
returns a read-only array from np.asarray() on a Series. rd.shuffle()
then fails with "ValueError: assignment destination is read-only",
which fails the cache build under `jb build -W` and leaves the four
figure labels in inequality.md undefined.

This did not surface in the dependabot PR checks: those restore the
existing build cache, and because no lecture content changed the
notebooks were never re-executed under the new anaconda. Only a
from-scratch cache.yml build exercises this path.

Use `.copy()` to obtain a writeable array, matching upstream.

Mirrors upstream changes in QuantEcon/lecture-python-intro.

Verified: reproducing a read-only array raises the identical error,
and .copy() resolves it.
Copilot AI review requested due to automatic review settings July 16, 2026 05:50
@netlify

netlify Bot commented Jul 16, 2026

Copy link
Copy Markdown

Deploy Preview for playful-platypus-17d3bb ready!

Name Link
🔨 Latest commit dce3885
🔍 Latest deploy log https://app.netlify.com/projects/playful-platypus-17d3bb/deploys/6a58712f1144800008123b57
😎 Deploy Preview https://deploy-preview-224--playful-platypus-17d3bb.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a failing lecture build under anaconda 2026.06 / pandas 3.0 by ensuring the array being shuffled is writeable, avoiding ValueError: assignment destination is read-only during notebook execution in jb build -W.

Changes:

  • Convert the repeated Series to a writeable NumPy array by taking a .copy() after np.asarray(...).
  • Add an inline comment documenting the pandas 3.0 Copy-on-Write behavior that motivated the change.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

Copy link
Copy Markdown

@github-actions
github-actions Bot temporarily deployed to pull request July 16, 2026 05:57 Inactive
@mmcky
mmcky merged commit 92eddaa into main Jul 16, 2026
8 checks passed
@mmcky
mmcky deleted the fix/inequality-readonly-array branch July 16, 2026 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants