Skip to content

five_preferences: read dataBHS from data-lectures, guard usetex for Colab - #12

Merged
mmcky merged 1 commit into
mainfrom
five-preferences-colab
Aug 19, 2026
Merged

five_preferences: read dataBHS from data-lectures, guard usetex for Colab#12
mmcky merged 1 commit into
mainfrom
five-preferences-colab

Conversation

@mmcky

@mmcky mmcky commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

The one-pass fix planned on the issue: this repo's byte-identical five_preferences.md copy had both blockers on the downloadable-notebook path, so they land together.

The .mat repoint 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 the dataBHS.csv in data-lectures round-trips the .mat's three (236,1) float64 arrays bit-exactly. The data[['c']].to_numpy() form keeps the (236,1) column shape the downstream diff/histogram code relies on — plain data['c'] would index-align the shifted Series subtraction into zeros. This also drops the scipy.io dependency. The now-orphaned lectures/dataBHS.mat copy 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.rc in the plotting-parameters cell and the later bare rc('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

…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>
Copilot AI lite review requested due to automatic review settings August 18, 2026 23:20
@netlify

netlify Bot commented Aug 18, 2026

Copy link
Copy Markdown

Deploy Preview for aesthetic-semifreddo-9db98b ready!

Name Link
🔨 Latest commit 35ba680
🔍 Latest deploy log https://app.netlify.com/projects/aesthetic-semifreddo-9db98b/deploys/6a84e8ca30c6290008666539
😎 Deploy Preview https://deploy-preview-12--aesthetic-semifreddo-9db98b.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

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') with pandas.read_csv(...) from QuantEcon/data-lectures and preserve the original (236, 1) column shape for downstream calculations.
  • Guard usetex configuration in both plotting cells so LaTeX-less runtimes don’t error at render time.
  • Drop the scipy.io import in favor of pandas.
Suppressed comments (1)

lectures/five_preferences.md:1936

  • If you define a single HAS_LATEX flag 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')
@mmcky
mmcky merged commit e1d0156 into main Aug 19, 2026
5 of 6 checks passed
@mmcky
mmcky deleted the five-preferences-colab branch August 19, 2026 04:07
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.

five_preferences: downloadable notebook cannot run — dataBHS.mat is not served by the site

2 participants