Repository navigation
Refuse disclosure codes that match nothing, and key UK regions on GSS codes - #638
Conversation
For a weight-matrix level, Release._groups checked that every child area had an entry in parent_of, but not that the entry was an area of the parent level. A mapping that spelt the parent codes another way left every group empty, so the nesting check passed with no finding. On the synthetic probe from the issue, a seat withheld because three records carry it went unflagged as soon as the regions were named differently. The check now raises DisclosureError and gives the count of unknown codes, never the codes. It checks the parent codes of the child areas the estimates hold; entries for other areas are ignored, as before. The probe is a test. Part of #625. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The release used PriorPublic cells as given. A cell whose area code matched no area of its level was ignored, so a cell that an earlier publication showed, and that this release withholds, still counted as hidden, and the checks that depend on it never ran. Regions published under one spelling and passed to a release that holds them under another matched nothing, without an error. check() now raises DisclosureError for a prior cell at a level the release holds whose area code is not an area of that level, whatever the cell's reform and year. It runs in check(), so the order in which estimates are added does not matter. Release() also refuses a prior cell with an unknown outcome. Cells at levels the release does not hold, or for reforms or years it does not hold, belong to other publications and stay allowed. The messages give the prior's name and the count of cells, never codes or values. Part of #625. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The adapter keyed regions on region_code_oa when the household output had it, else on the stored region. On a Microcosm local file that gave GSS codes such as E12000007; on a national dataset, the engine's enum names such as LONDON. Regional results published from the national dataset and passed as prior_public to a seat release from a local file therefore matched nothing. Regions are now always keyed on ONS GSS codes: E12000001 to E12000009 for England's nine regions, and the country codes W92000004, S92000003 and N92000002 for Wales, Scotland and Northern Ireland. The table is one constant, UK_REGION_GSS_CODES. It reads GSS codes, the pseudo codes W99999999, S99999999 and N99999999 that Microcosm writes for the nations, and the enum names, as strings, bytes or enum members. UNKNOWN and missing values are unassigned, so those households count in the nation but in no region. Any other value raises, with a count and never the values. Publishers must use the same GSS codes in parent_of and in the region cells of prior_public; the release check now raises on codes that match nothing. The docs set out the codes. Part of #625. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A fixed fragment for the release check, which now raises on parent_of codes and prior cells that match nothing instead of passing in silence, and a changed fragment for UK regions, which the adapter now keys on ONS GSS codes whatever the dataset stores. Part of #625. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@juaristi22 thanks, this is my review at Good to merge once CI is green. One should, the rest are nits. All three parts of #625 are fixed. On Findings
Still not caught (beyond the PR's own list)
What looks right
What I checked
🤖 Generated with Claude Code |
A prior cell at a held (level, reform, year) must name an area of those estimates; only a cell for a reform or year the release does not hold may name an area of any of the level's estimates. Before, an area that only another year held passed and then matched nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- compute_uk_geography_disclosure raises for a prior cell at a level that is neither a UK level nor one given in area_weights=. A release accepts such cells, since they may belong to other publications, so a misspelt level would leave a public cell counted as hidden. - A column that gives no household an area is skipped, so an empty region_code_oa falls back to the stored region. A requested level whose columns give no household an area raises a clear error instead of a KeyError from the check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The docs and changelog now say a prior on older boundaries raises even for a year the release does not hold, that the adapter refuses unknown levels, and that region weights passed with area_weights= must use GSS codes. An added fragment for UK_REGION_GSS_CODES makes the release a minor one, since region codes change and enum names now raise. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks Vahid. All six are in 863634c, d419e46 and 79f6b3a.
I added your Checks: the three touched suites (82 passed), |
…at alike The lambda's layout differed between the locked ruff and the one CI installs, so the format check failed in CI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes #625.
Summary
The release check matches areas by their code strings. Two of its inputs were never checked against the areas the release holds, so a mismatch made the nesting check and the prior-publication check find nothing, without an error. UK regions also came out under different spellings depending on the dataset. This PR makes each of these an error or a single scheme.
parent_of. For a weight-matrix level,Releasenow raisesDisclosureErrorwhen a child area maps to a code that is not an area of the parent level. Before, every parent group came out empty and the check passed.Prior publications.
Release.check()raises for anyprior_publiccell at a level the release holds whose area code is not an area of that level. When the release holds the cell's reform and year, the area must be one of those estimates'; otherwise any of the level's areas will do. This runs at the start ofcheck(), so the order estimates are added in doesn't matter. It also covers levels held only as references.Release()raises for a prior cell whose outcome is not one of the six outcomes.compute_uk_geography_disclosureraises for a prior cell whose level is neither a UK level (national,region,constituency,local_authority) nor one given inarea_weights=. A release can't tell a misspelt level from another publication's, but the adapter knows every UK level.UK regions are keyed on ONS GSS codes. This holds whether they come from
region_code_oaor from the engine'sregionenum, as strings, bytes or enum members:E12codes;W92000004,S92000003andN92000002;W/S/N99999999) map to those country codes;UNKNOWNand blank values are unassigned;The table is
UK_REGION_GSS_CODES. A regional release from a national dataset and a seat release from a local file now publish and match the same codes. The Autumn Budget dashboard uses the same scheme (Publish results by region and constituency through the disclosure layer uk-autumn-budget-dashboard-2026#48).Empty area columns. A column that gives no household an area is skipped, so an empty
region_code_oafalls back to the storedregion. A requested level whose columns give no household an area raises a clear error, instead of aKeyErrorfrom the check.Docs.
docs/disclosure.mdhas a new section on UK region codes. It explains that prior cells andparent_ofmatch by code, and that region weights passed witharea_weights=must use GSS codes too.Messages give counts and level names, never codes or values.
Behaviour changes
"R", and enum names inparent_of), and now use GSS codes.addedfragment forUK_REGION_GSS_CODESsets it.parent_ofandprior_publicnow raise.getpassif not set in env #48, already uses GSS codes.Still not caught
Releasecan't tell it from another publication's level.parent_ofthat uses valid codes but maps areas wrongly still passes. For example, a parent can be left with no children. That can't be an error, because a seat matrix may legitimately cover only part of the parent level.parent_ofare ignored. That is harmless, because missing child areas still raise.Tests (synthetic data only)
parent_ofusing the region level's own codes,check()returns three blockingrecoverable_remainderfindings.area_weights=.region_code_oa(blank, whitespace or missing) falls back toregion. A requested level whose column is empty raises.Checks run locally
tests/test_disclosure_release.py,tests/test_uk_geography_disclosure.pyandtests/test_disclosure_schema.py: 82 passed. CI runs the full suite.ruff format --check .andruff check .with ruff 0.17.1, the version CI installs: clean. The locked ruff (0.12.11) formats these files the same way..github/check-changelog.sh origin/main: passes (fixed, changed and added fragments).🤖 Generated with Claude Code