Repository navigation
Conversation
This was referenced Oct 8, 2026
Merged
Since #565 the nation regions filter the stored household region column, and policyengine.py lists which regions make up each nation. policyengine-uk keeps its own mapping in the formula that derives country from region. These tests take the expected nations from that formula, for every value of policyengine-uk's Region enum, so the two copies cannot drift apart unnoticed. A Hypothesis property checks region-only data with several people per household, separately ordered tables and str or bytes regions, and each nation runs end to end through the UK model. Fixes #569 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MaxGhenis
force-pushed
the
fix/558-uk-nation-scoping
branch
from
October 9, 2026 04:56
1f6d02f to
da51cf1
Compare
This branch has not been deployed
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 #569
What this adds
Since #565 (6.2.3), the UK nation regions filter the stored household
regioncolumn, andcountries/uk/regions.pylists which regions make up each nation. policyengine-uk keeps its own mapping in thecountryformula, which derivescountryfromregion.tests/test_uk_regions.pychecks the registry against_REGION_COUNTRIES, a hard-coded table in the test. Nothing checks either list against policyengine-uk.tests/test_uk_nation_model_agreement.pytakes the expected nations from policyengine-uk itself. A situation-basedpolicyengine_uk.Simulationcalculatescountryfor every value of itsRegionenum, UNKNOWN included, in about 0.3s.Region: each nation filter keeps exactly the regions policyengine-uk places in that nation, and UNKNOWN falls in none.No households found.Simulation(..., scoping_strategy=country/<nation>).run()runs through the UK model for all four nations. The input hasregionand nocountry, and includes an UNKNOWN household, which every nation filter drops before the model runs. The output'scountryis the nation. The existing tests apply the strategies directly.Scoping code is unchanged; it stays as #565 made it, filtering stored
regionwith no model calculation.What the tests catch
Mutation check: 14 mutants, each run against a copy.
tests/test_uk_regions.py, because main's tests compare the registry with a hard-coded table rather than with the model:Regionvalue that the formula defaults to England;LONDONfrom England, or adding UNKNOWN to it, fails this module, as it fails main's tests.Dropping the weights passes this module. Main's tests catch it.
Certified-data check of #565
#565 noted that the certified artifact was unvalidated. On
enhanced_frs_2024_25_year_2026.h5, with main at 07bae75 and policyengine-uk 2.102.3, each nation filter keeps exactly the households policyengine-uk'scountryassigns to that nation:The four sets are disjoint and cover all 52,846 households (31,458,548.32 weighted).
Simulation.run()forcountry/scotlandreturns the same 5,405 households and leaves the caller's tables unchanged.Not fixed here
Scoped UK runs give the region all £31.73bn of UK business rates and region-relative deciles and poverty lines (#567). On 6.2.3, scoped Scotland household net income is £103.98bn, against £139.15bn for the same households in the national run. This reaches API nation results once PolicyEngine/policyengine-sim-api#733 deploys 6.2.3.
History of this PR
It first fixed #558 (nation regions raising on data without
country) by having policyengine-uk calculatecountryon the unscoped dataset before filtering. #565 fixed the same failure while this was in review, filtering storedregion, and its repository guidance rules out a preliminary model calculation. So this PR now carries only the tests. The earlier commits (1f6d02f, b1e138d, f12e77f) remain in this PR's history.Tests: the new module (10 tests, about 4s),
test_uk_regions,test_scoping_strategy,test_region_group_strategy,test_filtering,test_entity_utils,test_entity_utils_characterizationandtest_regionpass locally on Python 3.13.Review: an independent Opus review agreed the change follows the repository guidance (the model runs only inside the test, never in scoping). It asked for a stronger property, UNKNOWN kept in the end-to-end input, and an accurate commit message. All three are done in da51cf1.
axiom: n/a: tests of region scoping in the analysis wrapper, no policy encoded
🤖 Generated with Claude Code