-
Notifications
You must be signed in to change notification settings - Fork 8
Add place-level (city) filtering for US impact analysis #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
- Add "place" to USRegionType and US_REGION_PREFIXES - Add parse_us_place_region() helper to parse "place/NJ-57000" format - Add _filter_us_simulation_by_place() method to filter by place_fips - Load state dataset when place region is specified, then filter 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add tests for determine_us_region_type with place regions - Add tests for parse_us_place_region function - Add tests for _get_default_us_dataset with place regions - Add tests for _filter_us_simulation_by_place method - Add mini dataset fixture for integration-style place filtering tests - Cover edge cases: bytes vs str place_fips, empty results, multiple places 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Create tests/fixtures/country/us_places.py with: - create_mock_simulation_with_place_fips() helper - create_mock_simulation_with_bytes_place_fips() helper - mini_place_dataset pytest fixture - mini_place_dataset_with_bytes pytest fixture - Update tests/fixtures/__init__.py to export new fixtures - Update tests/conftest.py to register fixtures globally - Refactor test_us_places.py to import from fixtures 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Extract hardcoded values from tests into fixtures: - Place FIPS constants (NJ_PATERSON_FIPS, etc.) - Region string constants (NJ_PATERSON_REGION, etc.) - Test data arrays (MIXED_PLACES_WITH_PATERSON, etc.) - Expected results constants (EXPECTED_PATERSON_COUNT_IN_MIXED, etc.) - Pre-configured mock fixtures for common test scenarios 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The "city" region type (previously used only for NYC) has been removed. Place-level filtering using "place/" prefix is now the standard approach for sub-state geographic filtering. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix place filtering to use map_to="person" for correct entity mapping - Add validation in parse_us_place_region() for: - Empty state codes - Empty place FIPS codes - Missing dash separator - Wrong prefix 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add changelog entry for place-level impact analysis feature - Format code with black 🤖 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>
The conftest.py was importing SimulationOptions from fixtures at module level, which triggered loading policyengine_us and policyengine_uk before any tests ran. This consumed significant memory at test collection time. Changed tests/fixtures/simulation.py to use lazy getter functions instead of module-level variables that call SimulationOptions.model_validate(). Updated tests/test_simulation.py to use the new getter functions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
f311bab to
60faa76
Compare
The national ECPS_2024 dataset is too large for the CI runner's memory (7GB). Changed tests to use Delaware state data instead, which tests the same simulation and comparison pipeline with much smaller memory footprint. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Added lazy import inside the test function. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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 #222
Summary
Changes
policyengine/utils/data/datasets.py"place"toUSRegionTypeliteral type"place"toUS_REGION_PREFIXEStupleparse_us_place_region()helper function to extract state code and place FIPS from region strings_get_default_us_dataset()to load the parent state's datasetpolicyengine/simulation.py"place/"regions in_apply_us_region_to_simulation()_filter_us_simulation_by_place()method that filters households byplace_fipsRegion String Format
place/{STATE_ABBREV}-{PLACE_FIPS}place/NJ-57000for Paterson, NJHow It Works
place_fipsvariable in the datasetTest plan
place/NJ-57000)🤖 Generated with Claude Code