Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/459.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Decode enum values to their names in US household calculation results.
9 changes: 8 additions & 1 deletion src/policyengine/tax_benefit_models/us/household.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,14 @@ def calculate_household(
result = HouseholdResult()
for entity, columns in output_columns.items():
raw = {
variable: list(simulation.calculate(variable, period=year, map_to=entity))
variable: list(
simulation.calculate(
variable,
period=year,
map_to=entity,
decode_enums=True,
)
)
for variable in columns
}
if entity == "person":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"person[0].medicare_cost": 0.0,
"person[0].person_id": 0.0,
"person[0].person_weight": 1.0,
"person[0].race": 3.0,
"person[0].race": "OTHER",
"person[0].social_security": 0.0,
"person[0].spm_unit_id": 0.0,
"person[0].ssi": 0.0,
Expand All @@ -42,7 +42,7 @@
"person[1].medicare_cost": 0.0,
"person[1].person_id": 1.0,
"person[1].person_weight": 1.0,
"person[1].race": 3.0,
"person[1].race": "OTHER",
"person[1].social_security": 0.0,
"person[1].spm_unit_id": 0.0,
"person[1].ssi": 0.0,
Expand All @@ -60,7 +60,7 @@
"person[2].medicare_cost": 0.0,
"person[2].person_id": 2.0,
"person[2].person_weight": 1.0,
"person[2].race": 3.0,
"person[2].race": "OTHER",
"person[2].social_security": 0.0,
"person[2].spm_unit_id": 0.0,
"person[2].ssi": 0.0,
Expand All @@ -78,7 +78,7 @@
"person[3].medicare_cost": 0.0,
"person[3].person_id": 3.0,
"person[3].person_weight": 1.0,
"person[3].race": 3.0,
"person[3].race": "OTHER",
"person[3].social_security": 0.0,
"person[3].spm_unit_id": 0.0,
"person[3].ssi": 0.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"person[0].medicare_cost": 0.0,
"person[0].person_id": 0.0,
"person[0].person_weight": 1.0,
"person[0].race": 3.0,
"person[0].race": "OTHER",
"person[0].social_security": 0.0,
"person[0].spm_unit_id": 0.0,
"person[0].ssi": 0.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"person[0].medicare_cost": 0.0,
"person[0].person_id": 0.0,
"person[0].person_weight": 1.0,
"person[0].race": 3.0,
"person[0].race": "OTHER",
"person[0].social_security": 0.0,
"person[0].spm_unit_id": 0.0,
"person[0].ssi": 0.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"person[0].medicare_cost": 0.0,
"person[0].person_id": 0.0,
"person[0].person_weight": 1.0,
"person[0].race": 3.0,
"person[0].race": "OTHER",
"person[0].social_security": 0.0,
"person[0].spm_unit_id": 0.0,
"person[0].ssi": 0.0,
Expand All @@ -42,7 +42,7 @@
"person[1].medicare_cost": 0.0,
"person[1].person_id": 1.0,
"person[1].person_weight": 1.0,
"person[1].race": 3.0,
"person[1].race": "OTHER",
"person[1].social_security": 0.0,
"person[1].spm_unit_id": 0.0,
"person[1].ssi": 0.0,
Expand Down
14 changes: 13 additions & 1 deletion tests/test_household_impact.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ def test__extra_variables_flat_list__then_values_appear_on_entity(self):
assert "adjusted_gross_income" in result.tax_unit
assert result.tax_unit.adjusted_gross_income > 0

def test__enum_extra_variable__then_returns_name(self):
result = pe.us.calculate_household(
spm={"geography_kind": "national"},
people=[{"age": 35, "is_tax_unit_head": True}],
household={"state_code": "CA"},
year=2026,
extra_variables=["state_name"],
)

assert result.household.state_name == "CA"

def test__axes__then_result_values_are_axis_series(self):
result = pe.us.calculate_household(
spm={"geography_kind": "national"},
Expand All @@ -197,7 +208,7 @@ def test__axes__then_result_values_are_axis_series(self):
"count": 3,
}
],
extra_variables=["charitable_cash_donations"],
extra_variables=["charitable_cash_donations", "state_name"],
)
assert result.person[0].charitable_cash_donations == [0, 5000, 10000]
# Donations reduce income tax via the charitable deduction; assert
Expand All @@ -208,6 +219,7 @@ def test__axes__then_result_values_are_axis_series(self):
assert income_tax[0] > income_tax[-1]
assert all(a >= b for a, b in zip(income_tax, income_tax[1:]))
assert len(result.household.household_net_income) == 3
assert result.household.state_name == ["CA", "CA", "CA"]

def test__nested_axes_shape__then_supported(self):
result = pe.us.calculate_household(
Expand Down
Loading