From dedaa9816e0e58b3096294dfff9df00a8af6b296 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 13 Oct 2026 04:08:46 +0000 Subject: [PATCH] [polars] Fetch the FRED CSV with requests before parsing it 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 Claude-Session: https://claude.ai/code/session_01Wyb6EzbNzY5a8uuJPnDtUb --- lectures/polars.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lectures/polars.md b/lectures/polars.md index 3b082d4e..741528f0 100644 --- a/lectures/polars.md +++ b/lectures/polars.md @@ -544,7 +544,8 @@ As in {doc}`pandas`, Python makes it straightforward to query online databases. An important database for economists is [FRED](https://fred.stlouisfed.org/) --- a vast collection of time series data maintained by the St. Louis Fed. -Polars' `read_csv` can fetch data from a URL directly. +We download the CSV file with [requests](https://requests.readthedocs.io/en/latest/) +and pass its contents to Polars' `read_csv`. We use `try_parse_dates=True` to parse the date column automatically @@ -564,7 +565,10 @@ fred_url = ('https://fred.stlouisfed.org/graph/fredgraph.csv?' 'fgst=lin&fgsnd=2020-02-01&line_index=1&' 'transformation=lin&vintage_date=2024-07-29&' 'revision_date=2024-07-29&nd=1948-01-01') -data = pl.read_csv(fred_url, try_parse_dates=True) +import requests + +r = requests.get(fred_url) +data = pl.read_csv(r.content, try_parse_dates=True) ``` Let's inspect the first few rows