Skip to content

Commit dedaa98

Browse files
committed
[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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Wyb6EzbNzY5a8uuJPnDtUb
1 parent 85586e6 commit dedaa98

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎lectures/polars.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,8 @@ As in {doc}`pandas`, Python makes it straightforward to query online databases.
544544

545545
An important database for economists is [FRED](https://fred.stlouisfed.org/) --- a vast collection of time series data maintained by the St. Louis Fed.
546546

547-
Polars' `read_csv` can fetch data from a URL directly.
547+
We download the CSV file with [requests](https://requests.readthedocs.io/en/latest/)
548+
and pass its contents to Polars' `read_csv`.
548549

549550
We use `try_parse_dates=True` to parse the date column automatically
550551

@@ -564,7 +565,10 @@ fred_url = ('https://fred.stlouisfed.org/graph/fredgraph.csv?'
564565
'fgst=lin&fgsnd=2020-02-01&line_index=1&'
565566
'transformation=lin&vintage_date=2024-07-29&'
566567
'revision_date=2024-07-29&nd=1948-01-01')
567-
data = pl.read_csv(fred_url, try_parse_dates=True)
568+
import requests
569+
570+
r = requests.get(fred_url)
571+
data = pl.read_csv(r.content, try_parse_dates=True)
568572
```
569573

570574
Let's inspect the first few rows

0 commit comments

Comments
 (0)