FIX: take writeable copy before rd.shuffle in inequality (pandas 3.0) - #224
Merged
Merged
Conversation
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.
✅ Deploy Preview for playful-platypus-17d3bb ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
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()afternp.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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mainis currently red: thecache.yml"Build Cache" run fails withbuild finished with problems, 6 warningsafter 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 ininequality.mdthen raises:Under
jb build -Wthat fails the build, so the job never reaches its artifact upload step. The fourundefined labelwarnings 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.ymlandci-cn.ymlrestore the existingbuild-cacheartifact, and because no lecture content changed, the notebooks were never re-executed under the new anaconda. Only a from-scratchcache.ymlbuild (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.
inequality.mdinput_output.mdquantecon_book_networksimports removedpkg_resourcesnetworks.mdinput_output.mdThe latter two do not affect us: both lectures install the package at build time with
!pip install quantecon_book_networksrather 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 forinput_outputornetworks.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 thecache.ymlrun after merge.Follow-up
After merge,
cache.ymlshould be dispatched to confirm the build goes green and to mint abuild-cacheartifact built against anaconda 2026.06 / quantecon-book-theme 0.21.0. The current artifact predates those bumps.🤖 Generated with Claude Code