fix(FR/IT): normalise state.level field for region/department hierarchy#1489
Merged
Conversation
Customer-facing follow-up to #1349 (Italy) and #1352 (France). Cities were re-parented onto departments (FR) and provinces (IT) by #1395 / #1394 / #1393 / #1400 / #1484, but the state records themselves still carried inconsistent 'level' values, blocking downstream filters like "all departments == level=2" or "all regions == level=1". bin/scripts/fixes/states_level_normalise.py drives the change: - FR: 29 region-tier rows None -> 1 (13 metro regions, 3 special metro collectivities incl. Corse + Alsace + Métropole de Lyon, 13 overseas regions/collectivities/territories/dependency). 95 metropolitan departments unchanged at level=2. - IT: 103 rows updated. Final state: 20 at level=1 (15 region + 5 autonomous region) and 106 at level=2 (80 province + 14 metropolitan city + 6 free municipal consortium + 4 decentralized regional entity + 2 autonomous province). Only the 'level' field is touched; idempotent on re-run; non-FR/IT states untouched. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Normalises state.level for France and Italy so consumers can reliably distinguish region-tier (level=1) vs department/province-tier (level=2) states, aligning state metadata with the already-correct city parenting from prior remap PRs.
Changes:
- Rewrites inconsistent/missing
levelvalues on FR/IT state records incontributions/states/states.jsonto a consistent1(region tier) or2(department/province tier). - Adds an idempotent fix script (
bin/scripts/fixes/states_level_normalise.py) to apply and validate the normalisation (including a parent-id integrity diagnostic).
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| contributions/states/states.json | Normalises FR/IT level values (regions/collectivities → 1, departments/provinces → 2). |
| bin/scripts/fixes/states_level_normalise.py | Adds a repeatable script to compute/apply the level normalisation and report unmapped types / parent-id issues. |
This was referenced Apr 27, 2026
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.
Summary
Customer-facing follow-up to #1349 / #1352. Cities are already correctly parented onto departments (FR) and provinces (IT) via the recently merged remap PRs (#1395, #1394, #1393, #1400, #1484), but the state rows themselves still carried inconsistent
levelvalues. This PR normalises the field so downstream consumers can reliably filterlevel=1(region) vslevel=2(department/province).Driven by
bin/scripts/fixes/states_level_normalise.py(idempotent, only toucheslevel, only on FR/IT).Before / After
France (FR)
null1229 rows
null → 1: 13 metropolitan regions, 2 metropolitan collectivities with special status (Paris, Métropole de Lyon), 1 European collectivity (Alsace), 5 overseas regions, 5 overseas collectivities, 1 overseas collectivity with special status (Nouvelle-Calédonie), 1 overseas territory (TAAF), 1 dependency (Clipperton). 95 metropolitan departments unchanged at2.Italy (IT)
null123103 rows updated. Final state:
level=1isregion(15) +autonomous region(5) = 20.level=2isprovince(80) +metropolitan city(14) +free municipal consortium(6) +decentralized regional entity(4) +autonomous province(2) = 106.Validation
levelfield was rewritten on 132 FR/IT rows; every other field byte-for-byte intact.country_id ↔ country_codeconsistent for all 250 FR/IT states; no duplicateids introduced.metropolitan department(level=2) has aparent_idresolving to a level=1 FR row, and every ITprovince/metropolitan city/free municipal consortium/decentralized regional entity/autonomous province(level=2) has aparent_idresolving to a level=1 IT row — with one pre-existing exception unrelated to this PR: 8 Tuscany provinces (Pisa,Pistoia,Prato,Siena,Livorno,Lucca,Massa and Carrara,Grosseto, ids 1685/1687/1700/1734/1745/1749/1759/1787) carryparent_id=1764("Udine", a Friuli decentralized regional entity) instead of1664("Tuscany"). This is a stale parent_id from feat(IT): remap cities to metropolitan cities and provinces (#1349) #1395 and is orthogonal to level normalisation; flagging here for a follow-up cleanup.Notes
id/created_at/updated_at/flagfields were added or modified.