Skip to content

feat: support multiple households in calculation endpoints#73

Merged
nwoodruff-co merged 3 commits intomainfrom
multi-household-support
Jan 13, 2026
Merged

feat: support multiple households in calculation endpoints#73
nwoodruff-co merged 3 commits intomainfrom
multi-household-support

Conversation

@nikhilwoodruff
Copy link
Contributor

Summary

Changed entity inputs from single dicts to lists of dicts, enabling callers to submit multiple households with entity relational dataframes. The caller specifies {entity}_id fields in each entity and person_{entity}_id fields in people to link them together.

Changes

  • Updated HouseholdCalculateRequest and HouseholdImpactRequest schemas: entity fields (benunit, marital_unit, family, spm_unit, tax_unit, household) changed from dict[str, Any] to list[dict[str, Any]]
  • Updated HouseholdCalculateResponse to return household as a list
  • Rewrote local calculation functions (_calculate_household_uk, _calculate_household_us) to build entity dataframes directly with proper ID relationships
  • Updated Modal functions (simulate_household_uk, simulate_household_us) with the same logic
  • Fixed imports for MicroDataFrame and UKYearData/USYearData
  • Added multi-household tests for both UK and US

Example

{
  "tax_benefit_model_name": "policyengine_us",
  "people": [
    {"person_id": 0, "person_household_id": 0, "person_tax_unit_id": 0, "age": 40, "employment_income": 70000},
    {"person_id": 1, "person_household_id": 1, "person_tax_unit_id": 1, "age": 30, "employment_income": 50000}
  ],
  "tax_unit": [
    {"tax_unit_id": 0, "state_code": "CA"},
    {"tax_unit_id": 1, "state_code": "NY"}
  ],
  "household": [
    {"household_id": 0, "state_fips": 6},
    {"household_id": 1, "state_fips": 36}
  ],
  "year": 2024
}

Testing

All 10 household tests pass, including 2 new multi-household tests.

Changed entity inputs from single dicts to lists of dicts, enabling
callers to submit multiple households with entity relational dataframes.
The caller specifies {entity}_id fields in each entity and
person_{entity}_id fields in people to link them together.

For simple single-household requests, IDs can be omitted and all people
will default to entity 0.

Co-Authored-By: Claude <noreply@anthropic.com>
@nwoodruff-co nwoodruff-co marked this pull request as ready for review January 13, 2026 10:27
nikhilwoodruff and others added 2 commits January 13, 2026 10:33
- Changed route paths from "/" to "" to avoid trailing slash mismatch
- Added simulation_id fixture to create test dependencies
- Updated tests to use the fixture instead of random UUIDs

Co-Authored-By: Claude <noreply@anthropic.com>
@nwoodruff-co nwoodruff-co merged commit 633576b into main Jan 13, 2026
1 check passed
@nwoodruff-co nwoodruff-co deleted the multi-household-support branch January 13, 2026 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants