-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c76194
commit a4fff74
Showing
4 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from policyengine_core.data import Dataset | ||
from policyengine_us_data.data_storage import STORAGE_FOLDER | ||
from pathlib import Path | ||
|
||
|
||
class IRS_PUF(Dataset): | ||
"""Dataset containing IRS PUF tables.""" | ||
|
||
puf_file_path: Path | ||
puf_demographics_file_path: Path | ||
data_format = Dataset.TABLES | ||
|
||
def generate(self): | ||
import pandas as pd | ||
|
||
puf_file_path = Path(self.puf_file_path).expanduser().resolve() | ||
puf_demographics_file_path = Path(self.puf_demographics_file_path).expanduser().resolve() | ||
|
||
if not puf_file_path.exists(): | ||
raise FileNotFoundError(f"PUF file not found at {puf_file_path}. Either put it there, or change {Path(__file__)} point to a different path.") | ||
|
||
if not puf_demographics_file_path.exists(): | ||
raise FileNotFoundError(f"PUF demographics file not found at {puf_demographics_file_path}. Either put it there, or change {Path(__file__)} point to a different path.") | ||
|
||
with pd.HDFStore(self.file_path, mode="w") as storage: | ||
storage.put("puf", pd.read_csv(puf_file_path)) | ||
storage.put("puf_demographics", pd.read_csv(puf_demographics_file_path)) | ||
|
||
|
||
class IRS_PUF_2015(IRS_PUF): | ||
name = "irs_puf_2015" | ||
label = "IRS PUF (2015)" | ||
time_period = 2015 | ||
puf_file_path = "~/Downloads/puf_2015.csv" | ||
puf_demographics_file_path = "~/Downloads/demographics_2015.csv" | ||
file_path = STORAGE_FOLDER / "irs_puf_2015.h5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize("year", [2015]) | ||
def test_irs_puf_generates(year: int): | ||
from policyengine_us_data.irs_puf import IRS_PUF_2015 | ||
|
||
dataset_by_year = { | ||
2015: IRS_PUF_2015, | ||
} | ||
|
||
dataset_by_year[year](require=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters