All checks were successful
CI / lint (push) Successful in 40s
CI / notebooks-smoke (push) Successful in 2m21s
Deploy / changes (push) Successful in 15s
Infra CI / notebooks (push) Successful in 53s
CI / test (push) Successful in 4m33s
Infra CI / zotero (push) Successful in 20s
Infra CI / docs (push) Successful in 25s
Infra CI / bcda (push) Successful in 1m36s
Infra CI / api (push) Successful in 2m14s
Infra CI / mc (push) Successful in 27s
Deploy / notebooks (push) Has been skipped
Deploy / zotero (push) Has been skipped
Deploy / docs (push) Has been skipped
Infra CI / llm (push) Successful in 1m11s
Deploy / api (push) Successful in 1m37s
Deploy / bcda (push) Successful in 1m52s
Deploy / mc (push) Has been skipped
Deploy / llm (push) Successful in 1m14s
Deploy / report (push) Successful in 15s
84 lines
2.5 KiB
Python
84 lines
2.5 KiB
Python
"""FRED observations and IRS SOI county income. No download."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from econ.fred import parse_observations
|
|
from econ.irs_soi import CountyIncome, parse_county_income
|
|
|
|
|
|
def test_fred_dot_value_is_missing():
|
|
rows = parse_observations({"observations": [{"date": "2024-01-01", "value": "."}]})
|
|
assert len(rows) == 1
|
|
assert rows[0].value is None
|
|
assert rows[0].year == 2024
|
|
assert rows[0].period == "2024-01-01"
|
|
|
|
|
|
def test_fred_missing_date_has_no_year():
|
|
rows = parse_observations({"observations": [{"date": "", "value": "1"}]})
|
|
assert rows[0].year is None
|
|
assert rows[0].value == 1.0
|
|
|
|
|
|
def test_county_income_keeps_the_fips_text():
|
|
rows = parse_county_income("fips,year,agi\n01001,2022,40000\n")
|
|
assert rows == (CountyIncome(fips="01001", year=2022, agi=40000),)
|
|
|
|
|
|
def test_blank_agi_is_none():
|
|
rows = parse_county_income("fips,year,agi\n01001,2022,\n")
|
|
assert rows[0].agi is None
|
|
|
|
|
|
def test_missing_column_raises():
|
|
with pytest.raises(ValueError):
|
|
parse_county_income("fips,year\n01001,2022\n")
|
|
|
|
|
|
def test_parse_fredgraph_csv():
|
|
from econ.fred import SeriesRow, parse_fredgraph_csv
|
|
|
|
text = "observation_date,CPIMEDSL\n1947-01-01,13.200\n2026-10-01,.\n"
|
|
assert parse_fredgraph_csv(text, "CPIMEDSL") == (
|
|
SeriesRow("CPIMEDSL", 1947, "1947-01-01", 13.2),
|
|
SeriesRow("CPIMEDSL", 2026, "2026-10-01", None),
|
|
)
|
|
|
|
|
|
def test_fredgraph_old_header():
|
|
from econ.fred import SeriesRow, parse_fredgraph_csv
|
|
|
|
text = "DATE,CPIMEDSL\n1947-01-01,13.200\n2026-10-01,.\n"
|
|
assert parse_fredgraph_csv(text, "CPIMEDSL") == (
|
|
SeriesRow("CPIMEDSL", 1947, "1947-01-01", 13.2),
|
|
SeriesRow("CPIMEDSL", 2026, "2026-10-01", None),
|
|
)
|
|
|
|
|
|
def test_fredgraph_html_rejected():
|
|
from econ.fred import parse_fredgraph_csv
|
|
|
|
with pytest.raises(ValueError):
|
|
parse_fredgraph_csv("<!DOCTYPE html><html></html>\n", "CPIMEDSL")
|
|
|
|
|
|
def test_soi_zip_sums_agi_stubs():
|
|
from econ.irs_soi import ZipIncome, parse_soi_zip
|
|
|
|
text = (
|
|
"STATEFIPS,STATE,ZIPCODE,AGI_STUB,N1,A00100\n"
|
|
"25,MA,1001,0,9999,9999\n"
|
|
"25,MA,1001,1,10,100\n"
|
|
"25,MA,1001,2,20,200\n"
|
|
"25,MA,1001,3,30,300\n"
|
|
"25,MA,1001,4,40,400\n"
|
|
"25,MA,1001,5,50,500\n"
|
|
"25,MA,1001,6,60,600\n"
|
|
"25,MA,1001,7,,\n"
|
|
"25,MA,00000,1,9,9\n"
|
|
"25,MA,99999,1,8,8\n"
|
|
)
|
|
assert parse_soi_zip(text, 2022) == (ZipIncome(2022, "01001", "25", 210, 2100),)
|