Add congressional district breakdowns to state-level simulations#217
Merged
Add congressional district breakdowns to state-level simulations#217
Conversation
- Add congressional_district_geoid to SingleEconomy model - Add us_congressional_district_breakdown() function mirroring UK constituency logic - Add USCongressionalDistrictImpact and USCongressionalDistrictBreakdownWithValues models - Add congressional_district_impact field to EconomyComparison - Add comprehensive tests following given-when-then naming pattern - Add mock fixtures for district testing The district-level calculations use identical formulas to UK parliamentary constituencies: - average_household_income_change = (reform.sum() - baseline.sum()) / count() - relative_household_income_change = reform.sum() / baseline.sum() - 1 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Move STATE_FIPS_TO_ABBREV mapping to utils/geography.py - Move geoid_to_district_name() function to utils/geography.py - Update imports in calculate_economy_comparison.py and tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #216
Summary
Adds congressional district-level breakdowns to US state-level simulation results, mirroring the existing UK parliamentary constituency breakdown functionality.
Changes
Core Implementation
policyengine/outputs/macro/single/calculate_single_economy.pycongressional_district_geoid: List[int] | NonetoSingleEconomymodelcalculate_congressional_district_geoid()method toGeneralEconomyTaskpolicyengine/outputs/macro/comparison/calculate_economy_comparison.pyUSCongressionalDistrictImpactmodel (per-district results)USCongressionalDistrictBreakdownWithValuesmodel (list of districts)us_congressional_district_breakdown()function using identical formulas to UK constituenciescongressional_district_impactfield toEconomyComparisongeoid_to_district_name()helper to convert SSDD format to "GA-05" style namesSTATE_FIPS_TO_ABBREVmappingTests
tests/country/test_us_congressional_districts.py(new file)tests/fixtures/simulation.pycreate_mock_single_economy()helpertests/conftest.pyandtests/fixtures/__init__.pyOutput Format
{ "congressional_district_impact": { "districts": [ { "district": "RI-01", "average_household_income_change": 320.73, "relative_household_income_change": 0.001944 }, { "district": "RI-02", "average_household_income_change": 199.13, "relative_household_income_change": 0.001132 } ] } }Verification
Tested with Rhode Island (2 districts) - making CTC fully refundable:
Formula Confirmation
The district-level calculations use identical formulas to UK parliamentary constituencies:
average_household_income_change(reform.sum() - baseline.sum()) / baseline.count()relative_household_income_changereform.sum() / baseline.sum() - 1Test Plan
geoid_to_district_name()us_congressional_district_breakdown()with mocked data