Skip to content

FIX: install quantecon in networks.md#802

Merged
mmcky merged 1 commit into
mainfrom
fix/networks-install-quantecon
Jul 24, 2026
Merged

FIX: install quantecon in networks.md#802
mmcky merged 1 commit into
mainfrom
fix/networks-install-quantecon

Conversation

@mmcky

@mmcky mmcky commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Closes #801.

lectures/networks.md imports quantecon at line 56 but its pip cell only installs quantecon-book-networks==1.6 and pandas-datareader. The lecture builds today because markov_chains_I (TOC 35), markov_chains_II (36) and eigen_II (40) each run !pip install quantecon into the same runner environment before networks (43) executes, and pip installs persist across notebooks within a build. A full cold build therefore satisfies the dependency by accident.

That guarantee disappears the moment the lecture executes on its own — which is the normal case, not an edge case. With a warm jupyter-cache, a one-line edit to networks.md re-executes only that notebook and serves every other lecture from cache, so none of the earlier pip cells fire. This was observed in the Chinese edition (lecture-intro.zh-cn#276), which carries the identical gap because it is a faithful translation of this file: ModuleNotFoundError: No module named 'quantecon' in the imports cell, after months of green builds.

Confirmed that quantecon is not in environment.yml either — it reaches the build environment only via lecture pip cells.

The change

One cell, in lectures/networks.md:

Before After
!pip install quantecon-book-networks==1.6 pandas-datareader !pip install quantecon
!pip install quantecon-book-networks==1.6
!pip install pandas-datareader

This follows the code style guide — packages outside the Anaconda distribution are installed at the top of the lecture that needs them, in their own standalone hide-output cell, one package per !pip install line. It also matches input_output.md, the sibling lecture that uses the same three packages. No prose changes, so there is nothing new for the translation editions to translate.

The wider check

The issue asked whether any other lecture imports a non-Anaconda package it does not itself install. I audited all 45 lectures — cross-referencing every import/from statement against the packages named in that lecture's own !pip install lines, for quantecon, quantecon_book_networks, wbgapi, yfinance, pandas_datareader, plotly, xlrd, graphviz, jax and interpolation. networks.md was the only lecture affected, and after this change the audit is clean.

🤖 Generated with Claude Code

`lectures/networks.md` imports `quantecon` but its pip cell never installs
it. The lecture builds today only because `markov_chains_I`, `markov_chains_II`
and `eigen_II` appear earlier in the TOC and install `quantecon` into the same
runner environment, so a full cold build satisfies the dependency by accident.

That breaks as soon as the lecture executes on its own — the normal case with a
warm `jupyter-cache`, where only the edited notebook is re-run. Observed in the
Chinese edition, which carries the same gap as a faithful translation.

Adds `quantecon` to the lecture's own pip cell and splits the cell to one
package per line, matching `input_output.md` and the style guide.

Closes #801

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 24, 2026 03:34
@netlify

netlify Bot commented Jul 24, 2026

Copy link
Copy Markdown

Deploy Preview for taupe-gaufre-c4e660 ready!

Name Link
🔨 Latest commit fb2f014
🔍 Latest deploy log https://app.netlify.com/projects/taupe-gaufre-c4e660/deploys/6a62dd644191d00008c0bd36
😎 Deploy Preview https://deploy-preview-802--taupe-gaufre-c4e660.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

This PR fixes a latent dependency-order issue in the networks lecture by ensuring quantecon is installed within lectures/networks.md itself, so the notebook can run successfully in isolation (e.g., under warm jupyter-cache) rather than relying on earlier lectures’ pip cells.

Changes:

  • Add an explicit !pip install quantecon to lectures/networks.md.
  • Split the existing combined install line into one-package-per-line installs for consistency with the documented lecture pattern.

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

@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown

@github-actions
github-actions Bot temporarily deployed to pull request July 24, 2026 03:43 Inactive
@github-actions
github-actions Bot temporarily deployed to pull request July 24, 2026 03:43 Inactive
@mmcky
mmcky merged commit c71e4a9 into main Jul 24, 2026
8 checks passed
@mmcky
mmcky deleted the fix/networks-install-quantecon branch July 24, 2026 03:44
@mmcky

mmcky commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

✅ Translation sync completed (zh-cn)

Target repo: QuantEcon/lecture-intro.zh-cn
Translation PR: QuantEcon/lecture-intro.zh-cn#277
Files synced (1):

  • lectures/networks.md

mmcky added a commit to QuantEcon/lecture-intro.zh-cn that referenced this pull request Jul 24, 2026
Matches the form landed upstream in QuantEcon/lecture-python-intro#802,
which follows the code style guide (one package per line, standalone
hide-output cell).
mmcky added a commit to QuantEcon/lecture-intro.zh-cn that referenced this pull request Jul 24, 2026
…ix one Chinese-in-mathtext label (#276)

* Register the CJK font in five lectures with Chinese figure labels

These five lectures set Chinese text on matplotlib figures but never
registered a CJK font, so matplotlib fell back to DejaVu Sans (which has
no CJK coverage) and every Chinese axis label, title and legend entry
rendered as blank boxes ("tofu"). Nothing errored and a valid PNG was
written each time, so the defect has been shipping silently on the
published site.

Adds this edition's standard font-configuration block to the first code
cell that imports matplotlib in each lecture, so it runs before any
figure is drawn:

    import matplotlib as mpl
    FONTPATH = "fonts/SourceHanSerifSC-SemiBold.otf"
    mpl.font_manager.fontManager.addfont(FONTPATH)
    plt.rcParams['font.family'] = ['Source Han Serif SC']

Affected: cagan_adaptive, equalizing_difference, lp_intro, networks, pv.

See #275

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* french_rev: move Chinese out of math mode in the log(real balances) ylabel

The English source writes this axis label as
'$\log(\mathrm{real\;balances})$', and the translation substituted the
Chinese straight into \mathrm{}. Mathtext has no CJK coverage, so all
four characters of 实际余额 rendered as blank boxes — matplotlib logs
"Font 'rm' does not have a glyph for ... substituting with a dummy
symbol" and writes the figure anyway, so the label has been shipping as
log(□□□□) on the published site.

The lecture's own font configuration is fine and the x-label immediately
above it already uses the correct pattern — Chinese as plain text, maths
inside $...$. This applies that pattern to the y-label, leaving \log and
its parentheses in math mode and the Chinese outside it. Rendered output
is unchanged in meaning: log(实际余额).

See #275

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Add a DejaVu fallback to font.family, and register the font in cagan_ree

Setting font.family to a single entry removes matplotlib's fallback, so any
character the CJK font lacks renders as a blank box. Source Han Serif SC follows
Adobe-GB1, which omits the symbol Greek forms (U+03D5 phi, U+03F5 epsilon),
subscript digits and the vertical ellipsis.

Measured on matplotlib 3.11.1 against this repo's own font:

    font.family = ['Source Han Serif SC']                  -> 4 missing-glyph warnings
    font.family = ['Source Han Serif SC', 'DejaVu Sans']   -> 0

cagan_ree.md already carried the block and was silently losing a character to
it: label=f'渐进 ϕ = {ϕ}' at line 783. Fixed by the fallback alone.

Deliberately deviates from the single-entry dialect used elsewhere here; the
dialect is missing a fallback and adding one is strictly an improvement.

* networks: install quantecon in its own pip cell

networks.md imports quantecon but its pip cell installed only
quantecon-book-networks and pandas-datareader. It has been relying on an earlier
lecture in the TOC having installed quantecon into the same runner: markov_chains_I
(33), markov_chains_II (34) and eigen_II (38) each do, and networks is at 41.

A full cold build therefore works, and the implicit dependency is invisible. It
only surfaces when networks.md executes alone -- which is exactly what happens
when a change invalidates its cache entry while every other lecture stays cached.
That is what broke this branch: the font block edit re-ran the notebook, none of
the earlier installs ran, and `import quantecon as qe` raised ModuleNotFoundError
at line 5 of the imports cell.

Makes the lecture self-sufficient, per the convention that packages outside
anaconda are installed at the start of the lecture that needs them.

The same gap exists upstream in QuantEcon/lecture-python-intro -- networks.md
there imports quantecon at line 56 with the same pip line at 19 -- so it is
inherited rather than a translation defect. Reported separately.

* networks: one package per pip install line

Matches the form landed upstream in QuantEcon/lecture-python-intro#802,
which follows the code style guide (one package per line, standalone
hide-output cell).

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

networks.md imports quantecon without installing it, relying on earlier lectures' pip cells

2 participants