From f336eec6625a949502a1c47ad0f16385b3a85e93 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Tue, 22 Sep 2026 17:50:07 +0400 Subject: [PATCH 1/2] Decode enum values in US household results --- changelog.d/459.fixed.md | 1 + .../tax_benefit_models/us/household.py | 9 ++++++++- tests/test_household_impact.py | 14 +++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 changelog.d/459.fixed.md diff --git a/changelog.d/459.fixed.md b/changelog.d/459.fixed.md new file mode 100644 index 00000000..82962ef3 --- /dev/null +++ b/changelog.d/459.fixed.md @@ -0,0 +1 @@ +Decode enum values to their names in US household calculation results. diff --git a/src/policyengine/tax_benefit_models/us/household.py b/src/policyengine/tax_benefit_models/us/household.py index 9801214b..17f828a4 100644 --- a/src/policyengine/tax_benefit_models/us/household.py +++ b/src/policyengine/tax_benefit_models/us/household.py @@ -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": diff --git a/tests/test_household_impact.py b/tests/test_household_impact.py index 56133b1a..b62656c8 100644 --- a/tests/test_household_impact.py +++ b/tests/test_household_impact.py @@ -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"}, @@ -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 @@ -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( From 2dfb2f9087e87bdeb4142c24e4713d27881794e5 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Tue, 22 Sep 2026 17:59:46 +0400 Subject: [PATCH 2/2] Update household enum snapshots --- .../us_married_two_kids_high_income.json | 8 ++++---- .../us_single_adult_employment_income.json | 2 +- .../us_single_adult_no_income.json | 2 +- .../us_single_parent_one_child.json | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/fixtures/household_calculator_snapshots/us_married_two_kids_high_income.json b/tests/fixtures/household_calculator_snapshots/us_married_two_kids_high_income.json index a3c2746f..a93ad3ea 100644 --- a/tests/fixtures/household_calculator_snapshots/us_married_two_kids_high_income.json +++ b/tests/fixtures/household_calculator_snapshots/us_married_two_kids_high_income.json @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/tests/fixtures/household_calculator_snapshots/us_single_adult_employment_income.json b/tests/fixtures/household_calculator_snapshots/us_single_adult_employment_income.json index e3a77657..17830104 100644 --- a/tests/fixtures/household_calculator_snapshots/us_single_adult_employment_income.json +++ b/tests/fixtures/household_calculator_snapshots/us_single_adult_employment_income.json @@ -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, diff --git a/tests/fixtures/household_calculator_snapshots/us_single_adult_no_income.json b/tests/fixtures/household_calculator_snapshots/us_single_adult_no_income.json index 8147e37e..0a455683 100644 --- a/tests/fixtures/household_calculator_snapshots/us_single_adult_no_income.json +++ b/tests/fixtures/household_calculator_snapshots/us_single_adult_no_income.json @@ -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, diff --git a/tests/fixtures/household_calculator_snapshots/us_single_parent_one_child.json b/tests/fixtures/household_calculator_snapshots/us_single_parent_one_child.json index 1160dde0..68a77c49 100644 --- a/tests/fixtures/household_calculator_snapshots/us_single_parent_one_child.json +++ b/tests/fixtures/household_calculator_snapshots/us_single_parent_one_child.json @@ -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, @@ -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,