Skip to content

Conversation

@anth-volk
Copy link
Collaborator

@anth-volk anth-volk commented Dec 8, 2025

Fixes #2961

Summary

This PR enables US Congressional district-level simulations in the PolicyEngine API. It adds support for running economy/macro simulations at the congressional district level, alongside the existing state and national levels.

Key Changes

  • Congressional Districts Data Module (policyengine_api/data/congressional_districts.py): New module containing metadata for all 435 US Congressional districts, including district codes, state associations, and validation utilities
  • Region Handling (policyengine_api/services/economy_service.py):
    • Added _setup_region() to properly prefix regions (e.g., castate/ca, TX-14congressional_district/TX-14)
    • Added _validate_us_region() to validate US states and congressional districts
    • Restored _setup_data() to handle NYC special pooled CPS dataset requirement
  • API Metadata (policyengine_api/country.py, policyengine_api/constants.py): Congressional district metadata is now included in the /metadata endpoint response
  • Package Update (setup.py): Upgraded policyengine dependency to >=0.7.0 to support district-level simulations

Region Format

The API now supports the following region formats for US simulations:

  • National: us
  • State: ca, tx, ny (automatically prefixed to state/ca, etc.)
  • Congressional district: TX-14, CA-37 (automatically prefixed to congressional_district/TX-14, etc.)
  • NYC: nyc (uses pooled 3-year CPS dataset)

Test Plan

  • Unit tests for congressional districts validation and lookup functions
  • Unit tests for _setup_region() method
  • Unit tests for _validate_us_region() method
  • Unit tests for _setup_data() method (NYC handling)
  • Updated existing _setup_sim_options() tests

@codecov
Copy link

codecov bot commented Dec 9, 2025

Codecov Report

❌ Patch coverage is 95.65217% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.87%. Comparing base (10067e3) to head (1c10af2).
⚠️ Report is 25 commits behind head on master.

Files with missing lines Patch % Lines
policyengine_api/services/economy_service.py 88.46% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2962      +/-   ##
==========================================
+ Coverage   74.09%   74.87%   +0.77%     
==========================================
  Files          53       54       +1     
  Lines        1965     2026      +61     
  Branches      254      268      +14     
==========================================
+ Hits         1456     1517      +61     
+ Misses        460      459       -1     
- Partials       49       50       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@anth-volk anth-volk marked this pull request as ready for review December 9, 2025 11:59
@anth-volk anth-volk force-pushed the feat/enable-us-districts branch from f52066d to 90aa695 Compare December 9, 2025 16:55
@anth-volk
Copy link
Collaborator Author

Waiting to merge this until we have an accompanying front-end PR ready.

@anth-volk anth-volk force-pushed the feat/enable-us-districts branch from 49ca90b to 1c10af2 Compare December 11, 2025 11:22
@anth-volk anth-volk merged commit d4b4b94 into master Dec 11, 2025
7 checks passed
@anth-volk anth-volk deleted the feat/enable-us-districts branch December 11, 2025 11:59
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.

Enable US congressional districts

2 participants