five_preferences: read dataBHS from data-lectures, guard usetex for Colab - #12
Merged
Conversation
…olab Mirrors the wave-C2 repoint in QuantEcon/lecture-python-advanced.myst#375 (the CSV round-trips the .mat's three (236,1) arrays bit-exactly; the column read keeps that shape via data[['c']].to_numpy()) and the usetex guard in QuantEcon/lecture-python-advanced.myst#378 — this copy carries the setting twice, so both sites are guarded. Together these make the downloadable five_preferences.ipynb runnable outside the build image: the site never served dataBHS.mat, and Colab has no latex binary. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
✅ Deploy Preview for aesthetic-semifreddo-9db98b ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
Updates the five_preferences lecture to ensure the downloadable notebook runs in environments like Colab by switching the BHS dataset load to a served, HTTP-accessible CSV and by guarding usetex so LaTeX rendering is only enabled when available.
Changes:
- Replace
loadmat('dataBHS.mat')withpandas.read_csv(...)fromQuantEcon/data-lecturesand preserve the original(236, 1)column shape for downstream calculations. - Guard
usetexconfiguration in both plotting cells so LaTeX-less runtimes don’t error at render time. - Drop the
scipy.ioimport in favor ofpandas.
Suppressed comments (1)
lectures/five_preferences.md:1936
- If you define a single
HAS_LATEXflag in the earlier plotting-parameters cell, reuse it here to avoid re-checking the environment and to keep the toggle consistent across the notebook.
rc('text', usetex=bool(shutil.which('latex')))
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+79
to
+82
| # Render text with LaTeX only where a latex binary exists (the build has | ||
| # texlive); on latex-less runtimes such as Colab, fall back to mathtext | ||
| # instead of raising at the first rendered figure. | ||
| plt.rc('text', usetex=bool(shutil.which('latex'))) |
|
|
||
| # Load data | ||
| data = loadmat('dataBHS.mat') | ||
| data = pd.read_csv('https://github.com/QuantEcon/data-lectures/raw/main/lectures/dataBHS.csv') |
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.
The one-pass fix planned on the issue: this repo's byte-identical
five_preferences.mdcopy had both blockers on the downloadable-notebook path, so they land together.The
.matrepoint mirrors QuantEcon/lecture-python-advanced.myst#375:loadmat('dataBHS.mat')read a file the published site never serves (404 measured on the issue, with a control), while thedataBHS.csvin data-lectures round-trips the.mat's three (236,1) float64 arrays bit-exactly. Thedata[['c']].to_numpy()form keeps the (236,1) column shape the downstream diff/histogram code relies on — plaindata['c']would index-align the shifted Series subtraction into zeros. This also drops thescipy.iodependency. The now-orphanedlectures/dataBHS.matcopy is left for the orphan sweep rather than deleted here.The usetex guard mirrors QuantEcon/lecture-python-advanced.myst#378, applied to both sites in this copy (
plt.rcin the plotting-parameters cell and the later barerc('text',usetex=True)cell): the build keeps LaTeX typography (CI installs texlive), while Colab and other latex-less runtimes fall back to mathtext instead of raising at the first rendered figure.Closes #11
🤖 Generated with Claude Code