Add ability to run impacts over subnational regions#231
Merged
anth-volk merged 8 commits intoapp-v2-migrationfrom Feb 16, 2026
Merged
Add ability to run impacts over subnational regions#231anth-volk merged 8 commits intoapp-v2-migrationfrom
anth-volk merged 8 commits intoapp-v2-migrationfrom
Conversation
This was referenced Feb 11, 2026
0fa4e96 to
ef193d5
Compare
- Remove unused imports - Sort imports correctly - Format code with ruff 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The sample_registry fixture was not being discovered by pytest after linting removed unused imports. Moving fixture imports to conftest.py is the standard pytest pattern for shared fixtures. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add filter_field and filter_value parameters to Simulation class - Add _build_entity_relationships() to US and UK models for mapping persons to all containing entities - Add _filter_dataset_by_household_variable() to filter datasets while preserving entity integrity - Apply filtering in run() method when filter parameters are set This enables filtering datasets by household-level variables like place_fips (US) or country (UK) for regional analysis. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add filtering_fixtures.py with US and UK test datasets - Add 18 unit tests for _build_entity_relationships and _filter_dataset_by_household_variable methods - Tests follow given-when-then pattern - All tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The US country package uses a shared singleton TaxBenefitSystem, which means p.update() after Microsimulation construction has no effect on calculations. This fix: - Adds reform_dict_from_parameter_values() utility to convert ParameterValue objects to the dict format accepted by Microsimulation - Updates US model.py to build reform dict and pass it at construction time instead of using simulation_modifier (p.update) after - Adds comprehensive unit tests for the utility function and US reform application The UK model continues to use p.update() since policyengine-uk was refactored to give each simulation its own TaxBenefitSystem instance. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove unused imports in test_us_reform_application.py. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ef193d5 to
2f52b03
Compare
Extract duplicated entity relationship and dataset filtering logic from US and UK model.py into shared utils/entity_utils.py. Decompose inline reform dict construction in US run() into single-purpose functions (build_reform_dict, merge_reform_dicts) in utils/parametric_reforms.py. Co-Authored-By: Claude Opus 4.6 <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 #230
Fixes #232
Summary
Add support for running policy impact calculations at subnational geographic levels, and fix US reform application.
Changes
Core Region Model (
src/policyengine/core/region.py)Regionclass with code, label, type, and optional dataset paths (HuggingFace/GCS)RegionRegistryfor O(1) lookups by code or type with automatic index rebuildingUS Regions (
src/policyengine/countries/us/)UK Regions (
src/policyengine/countries/uk/)US Reform Application Fix (#232)
reform_dict_from_parameter_values()utility to convert ParameterValue objects to reform dict formatmodel.pyto pass reforms atMicrosimulationconstruction time instead of usingp.update()after constructionIntegration
TaxBenefitModelVersion.regionsproperty for accessing region registriesTesting
RegionandRegionRegistryclassesreform_dict_from_parameter_values()utility (12 tests)Verification
Verified budgetary impacts at 3 geographic levels with CTC increase reform:
Subnational impacts are proportional to population shares, confirming correct calculation.
Verified US reform application fix: