Repository navigation
[polars] Fetch the FRED CSV with requests before parsing it - #647
Conversation
polars 2.0.0 (2026-10-06) reads a URL through its object store: it sends a HEAD request for the file size, then ranged GETs. FRED's fredgraph.csv answers HEAD with Content-Length: 0 (the body is ~14 kB), and polars 2.0 then stalls instead of erroring. The lecture installs the newest polars, so the FRED cell has hung until the 600 s cell timeout since the release, failing the weekly cache build on 2026-10-12 (it passed on 2026-10-05). Download the file with requests and pass the bytes to pl.read_csv. This reads the same 918 rows with the date column parsed under both polars 1.44.2 and 2.0.0. The sentence above the cell no longer says read_csv fetches the URL itself. All 52 code cells of the lecture run under polars 2.0.0 with live FRED and Yahoo Finance data. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Wyb6EzbNzY5a8uuJPnDtUb
There was a problem hiding this comment.
🟡 Changes recommended
The fix is correct, but the newly added import requests is placed mid-cell, deviating from the lecture's convention of grouping imports at the top.
1 open finding
What changed in this PR
This PR fixes the weekly cache build, which has been failing since polars 2.0.0 (released 2026-10-06). In the polars lecture, pl.read_csv(fred_url, ...) relies on polars reading the URL directly through its object store; under polars 2.0, FRED's fredgraph.csv returns content-length: 0 on HEAD, causing the read to stall until the 600 s cell timeout. The fix downloads the CSV with requests first and passes the bytes to pl.read_csv, which aligns with how the pandas lecture already fetches FRED data.
Changes:
- Download the FRED CSV via
requests.get(...)and passr.contenttopl.read_csvinstead of letting polars fetch the URL. - Update the surrounding prose so it describes the
requestsdownload rather thanread_csvfetching the URL.
| File | Description |
|---|---|
| lectures/polars.md | Fetch the FRED CSV with requests and pass the bytes to pl.read_csv; update the explanatory sentence accordingly. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
✅ Translation sync completed (zh-cn)Target repo: QuantEcon/lecture-python-programming.zh-cn
|
✅ Translation sync completed (fr)Target repo: QuantEcon/lecture-python-programming.fr
|
✅ Translation sync completed (fa)Target repo: QuantEcon/lecture-python-programming.fa
|

Problem
The weekly cache build has failed since polars 2.0.0 was released on 2026-10-06. It passed on 2026-10-05 and failed on 2026-10-12.
polars.mdhits the 600 s cell timeout on this line:The lecture runs
!pip install --upgrade polars yfinance, so CI gets the newest polars. The zh-cn edition fails in the same place, and its execution report names this cell.Cause
polars 2.0 reads a URL through its object store. It sends a
HEADrequest for the file size, then rangedGETs. FRED'sfredgraph.csvanswersHEADwithcontent-length: 0, although the body is 13,809 bytes. Ranged GETs work (206,content-range: bytes 0-3/13809). polars 2.0 then stalls instead of raising.Run against the real URL:
pl.read_csv(fred_url, try_parse_dates=True)Fix
Download the CSV with
requestsand pass the bytes topl.read_csv. This gives 918 rows with theobservation_datecolumn parsed asDateunder both 1.44.2 and 2.0.0. The sentence above the cell saidread_csvfetches the URL itself, so it now describes the download.This also matches the approach the pandas lecture already takes in its FRED section.
Testing
I ran all 52 code cells of the patched lecture under polars 2.0.0 and yfinance 1.7.0, with live FRED and Yahoo Finance data. All passed. The GitHub-hosted
test_pwt.csvcells, which are untouched, also read fine under 2.0.🤖 Generated with Claude Code
https://claude.ai/code/session_01Wyb6EzbNzY5a8uuJPnDtUb
Generated by Claude Code