Skip to content

P4: the business_cycle snapshot set — three World Bank tables and a FRED composite - #114

Merged
mmcky merged 2 commits into
mainfrom
p4-business-cycle-set
Sep 1, 2026
Merged

P4: the business_cycle snapshot set — three World Bank tables and a FRED composite#114
mmcky merged 2 commits into
mainfrom
p4-business-cycle-set

Conversation

@mmcky

@mmcky mmcky commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Stage 1 of re-enabling business_cycle in lecture-wasm (QuantEcon/lecture-wasm#70): after this PR, every live read that lecture makes has a snapshot here. lecture-python-intro keeps its live calls — the API is the lesson there — so this changes nothing a reader sees today; it creates the files the wasm edition will read.

Design, as decided today. One builder per source, a composite file where a lecture reads several series together, and a shared fetch librarybuilders/_fred.py, the Fred class over fredgraph.csv, so a FRED builder's fetch is one line and its validate() is the only thing worth reading. No pandas_datareader in a builder (the recommendation on #26, now acted on). Filenames of the three new files are provisional per the naming-policy discussion (#113) and free to change while consumers is empty; business_cycle_data.csv keeps its name.

What lands

File Builder Contents Cadence
business_cycle_data.csv business_cycle.py GDP growth, grown from 5 economies to the 9 the lecture plots (union of its two selections) — free while it has no consumer annual
unemployment_rate_annual.csv (new) business_cycle.py SL.UEM.TOTL.NE.ZS, USA FRA GBR JPN annual
private_credit_to_gdp.csv (new) business_cycle.py FS.AST.PRVT.GD.ZS, GBR annual
us_business_cycle_monthly.csv (new) business_cycle_fred.py on _fred.py UNRATE, USREC, UMCSENT, CPILFESL, INDPRO, M0892AUSM156SNBR on one monthly grid, 1919-01 → 2026-07 (1,291 rows) monthly — the first

Validation is about where nulls are, not how many. The World Bank tables allow a null only before an economy's first observation (UK unemployment starts 1971, France 1970) or in the newest two years (private credit's 2025 is unpublished) — never inside a series. The FRED composite declares every structural null exactly: series starts, UMCSENT's sparse pre-1978 sampling, the historical series' 1942-06 end, and the 2025-10 hole in UNRATE and CPILFESL (the shutdown month BLS never published) — so a second such month fails the refresh for a human rather than shipping. Revisions are bounded per series (CPILFESL and INDPRO are revised; USREC never). A builder that writes a set validates all three before writing any.

Licence. World Bank: CC BY-4.0. FRED: five series are federal/NBER; UMCSENT is the one third-party series, and FRED's page classifies it "copyrighted: citation required" — permitted with attribution, which is what this repo's cache-with-attribution policy provides, so redistribution: permitted with the reasoning in the note. Nothing new for #35.

Also in this PR. scripts/snapshots.py accepts a list summary from a multi-file builder and compares a date-shaped date_range.end as text — the stamp's read-back guard (from the Copilot review on #110) caught exactly that mismatch on the first try, refused to write, and this is the fix. All four manifests were stamped by snapshots.py rather than by hand.

Gates. check_consumed_files: 44 manifests, 0 errors. Strict audit against local clones: no new problems (several old ones cleared because the clones were fast-forwarded). snapshots.py: four snapshots listed, all verified, none due; the weekly canary will exercise both builders from Monday.

Next (QuantEcon/lecture-wasm#70): the wasm lecture edit reading these four URLs, then the flip here — consumers with on_refresh: rebuild, migration.yml → repointed.

See #26, #113, #14.

🤖 Generated with Claude Code

…RED composite

Stage 1 of re-enabling business_cycle in lecture-wasm (lecture-wasm#70):
every live read the lecture makes now has a snapshot here, with intro
keeping its live calls as the lesson.

- builders/_fred.py: the shared Fred class (fredgraph.csv over urllib,
  DATE index, `.` -> NaN, server-side frequency change). No
  pandas_datareader in a builder — the decision on #26.
- builders/business_cycle_fred.py -> lectures/us_business_cycle_monthly.csv:
  UNRATE, USREC, UMCSENT, CPILFESL, INDPRO and the 1929-42 NBER
  unemployment series on one monthly grid from 1919-01. validate() places
  every null exactly (series starts, UMCSENT's sparse pre-1978 years, the
  2025-10 shutdown hole in UNRATE and CPILFESL) and bounds revisions per
  series. cadence: monthly — the first.
- builders/business_cycle.py now writes three tables from one WDI fetch:
  business_cycle_data.csv grown from five economies to the nine the lecture
  plots (free while it has no consumer), unemployment_rate_annual.csv (USA
  FRA GBR JPN) and private_credit_to_gdp.csv (GBR). Nulls are placed, not
  counted: only before an economy's first observation or in the newest two
  years. All three validate before any writes. --summary-json emits a list.
- scripts/snapshots.py accepts a list summary and compares a date-shaped
  date_range.end as text (the stamp's read-back guard caught the mismatch).
- Manifests for the three new files (names provisional pending #113),
  business_cycle_data.csv.yml updated for nine economies, all four stamped
  by snapshots.py (retrieved, sha256, verified, date_range.end);
  migration.yml records (landed, P4); CATALOG.md regenerated; PLAN P4 box
  reframed; builders/README and AGENTS record the per-source rule.

UMCSENT's licence is recorded from FRED's own classification ("copyrighted:
citation required") as permitted-with-attribution, the condition this
repo's policy meets.

Gates: check_consumed_files 44/0; strict audit adds no problems; all four
snapshots list as verified and not due.

See #26, #113, #14; QuantEcon/lecture-wasm#70.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

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

Adds the remaining business_cycle snapshot set needed to re-enable the lecture in lecture-wasm by introducing three new published datasets (two WDI annual tables and one composite monthly FRED table), plus the corresponding builders and a small snapshots.py enhancement to support multi-file builder summaries.

Changes:

  • Add three new datasets + manifests: unemployment_rate_annual.csv, private_credit_to_gdp.csv, and us_business_cycle_monthly.csv (dynamic snapshots; annual/monthly cadences).
  • Extend builders/business_cycle.py to build/validate/write a 3-file WDI set; add builders/_fred.py and builders/business_cycle_fred.py for the composite FRED monthly dataset.
  • Update scripts/snapshots.py, PLAN.md, migration.yml, and regenerate CATALOG.md / builders docs to reflect the new snapshot set and stamping behavior.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
scripts/snapshots.py Supports multi-file builder summaries during stamp/pr-body generation; adjusts date-shaped end comparison.
PLAN.md Reframes P4 scope/status to the broader business_cycle snapshot set.
migration.yml Registers the three newly landed datasets under pilot P4.
lectures/us_business_cycle_monthly.csv.yml Manifest for new monthly composite FRED snapshot (provisional filename, monthly cadence).
lectures/us_business_cycle_monthly.csv New monthly composite dataset (1919-01..2026-07 grid).
lectures/unemployment_rate_annual.csv.yml Manifest for new WDI unemployment annual snapshot (4 economies).
lectures/unemployment_rate_annual.csv New annual unemployment dataset (wide YR#### columns).
lectures/private_credit_to_gdp.csv.yml Manifest for new WDI private credit-to-GDP annual snapshot (GBR).
lectures/private_credit_to_gdp.csv New annual private credit dataset (wide YR#### columns).
lectures/business_cycle_data.csv.yml Updates GDP-growth snapshot description/shape to 9 economies; stamps integrity/date_range updates.
lectures/business_cycle_data.csv Expands GDP-growth data to include additional economies.
CATALOG.md Regenerates catalog counts and adds the three new datasets.
builders/README.md Documents the new shared _fred.py and the expanded business_cycle builder set.
builders/business_cycle.py Refactors builder to produce/validate/write a 3-file WDI set with per-file summaries.
builders/business_cycle_fred.py New builder for the composite monthly FRED snapshot, using _fred.py.
builders/_fred.py New shared FRED fetch helper used by FRED builders.
AGENTS.md Records the “one builder per source + composite + shared fetch lib” decision and references _fred.py.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread scripts/snapshots.py
Comment thread builders/_fred.py
Comment thread builders/business_cycle_fred.py
…ast before validate

snapshots.py: the dataset-mismatch guard moves into _load_summary(), so
pr-body refuses a foreign or missing summary exactly as stamp does instead
of raising KeyError. _fred.py: the query string goes through
urllib.parse.urlencode. business_cycle_fred.py: pre_process() no longer
casts USREC — a `.` from FRED would have raised ValueError with exit 1 (a
retry) instead of a ValidationError with exit 2 (a human); validate() now
asserts USREC is complete and 0/1, and run() casts after validation.
Output bytes unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mmcky
mmcky merged commit ebb1bd1 into main Sep 1, 2026
4 checks passed
@mmcky
mmcky deleted the p4-business-cycle-set branch September 1, 2026 06:02
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