Skip to content

Commit 35c5ae6

Browse files
Add test for small ECPS (#306)
* Add test for small ECPS Fixes #305 * Cast to dataframe * Pin microimpute * Handle str data type * Rename test
1 parent e100c30 commit 35c5ae6

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

changelog_entry.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- bump: patch
2+
changes:
3+
added:
4+
- Add test for small ECPS.

policyengine_us_data/datasets/cps/cps.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@ def add_tips(self, cps: h5py.File):
740740
],
741741
2025,
742742
)
743+
cps = pd.DataFrame(cps)
743744

744745
cps["is_under_18"] = cps.age < 18
745746
cps["is_under_6"] = cps.age < 6

policyengine_us_data/datasets/cps/small_cps.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ def create_small_cps():
55
from policyengine_us import Microsimulation
66
from policyengine_us_data.datasets import EnhancedCPS_2024
77
from policyengine_us_data.storage import STORAGE_FOLDER
8+
from policyengine_core.enums import Enum
89

910
simulation = Microsimulation(
1011
dataset=EnhancedCPS_2024,
@@ -16,8 +17,13 @@ def create_small_cps():
1617
for time_period in simulation.get_holder(variable).get_known_periods():
1718
values = simulation.get_holder(variable).get_array(time_period)
1819
values = np.array(values)
20+
if simulation.tax_benefit_system.variables.get(
21+
variable
22+
).value_type in (Enum, str):
23+
values = values.astype("S")
1924
if values is not None:
2025
data[variable][time_period] = values
26+
2127
if len(data[variable]) == 0:
2228
del data[variable]
2329

@@ -28,3 +34,8 @@ def create_small_cps():
2834
grp = f.create_group(variable)
2935
for period, values in periods.items():
3036
grp.create_dataset(str(period), data=values)
37+
38+
39+
if __name__ == "__main__":
40+
create_small_cps()
41+
print("Small CPS dataset created successfully.")
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pytest
2+
import numpy as np
3+
4+
5+
@pytest.mark.parametrize("year", [2024])
6+
def test_small_cps_loads(year: int):
7+
from policyengine_core.data import Dataset
8+
from policyengine_us_data.storage import STORAGE_FOLDER
9+
from policyengine_us import Microsimulation
10+
11+
sim = Microsimulation(
12+
dataset=Dataset.from_file(
13+
STORAGE_FOLDER / f"small_cps_{year}.h5",
14+
)
15+
)
16+
17+
assert not sim.calculate("household_net_income", 2025).isna().any()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies = [
2323
"tqdm",
2424
"microdf_python>=0.4.3",
2525
"setuptools>=60",
26-
"microimpute>=0.1.4",
26+
"microimpute==0.1.4",
2727
"pip-system-certs",
2828
"google-cloud-storage",
2929
"google-auth",

0 commit comments

Comments
 (0)