Create dynamic country/NUTS region mapping via Eurostat with robust fallback#42
Draft
Create dynamic country/NUTS region mapping via Eurostat with robust fallback#42
Conversation
Agent-Logs-Url: https://github.com/maxnutz/pypsa_validation_processing/sessions/2b02bd67-ebd8-44a4-83a0-79efdb83a7af Co-authored-by: maxnutz <81740567+maxnutz@users.noreply.github.com>
Agent-Logs-Url: https://github.com/maxnutz/pypsa_validation_processing/sessions/2b02bd67-ebd8-44a4-83a0-79efdb83a7af Co-authored-by: maxnutz <81740567+maxnutz@users.noreply.github.com>
Agent-Logs-Url: https://github.com/maxnutz/pypsa_validation_processing/sessions/2b02bd67-ebd8-44a4-83a0-79efdb83a7af Co-authored-by: maxnutz <81740567+maxnutz@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Create country-codes and region-codes dynamically
Create dynamic country/NUTS region mapping via Eurostat with robust fallback
Apr 20, 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.
This change removes hard-coded country/NUTS mappings and builds
REGION_MAPPINGdynamically from Eurostat data (countries + EU-wide NUTS2/NUTS3), while preserving current consumer behavior. It also adds deterministic fallback behavior so mapping remains stable when Eurostat data is unavailable or incomplete.Dynamic mapping pipeline in
utils.pyget_country_mapping()get_nuts_mapping(level, country_prefix=None)create_region_mapping()^[A-Z]{2}$^[A-Z]{2}[A-Z0-9]{2}$^[A-Z]{2}[A-Z0-9]{3}$countries -> NUTS2 -> NUTS3 -> COUNTRIES_SPECIAL_CASESCompatibility and resilience
REGION_MAPPINGas a plaindict[str, str](no downstream interface changes).REGION_MAPPING.get(code, code)remains valid).Dependency updates
eurostatto project dependencies in:pixi.tomlpyproject.tomlTest suite updates (mapping-focused)
tests/test_utils.pyto cover:tests/test_network_processor.pytests/test_aggregation.pymap_country_codes_to_names=Truevs disabled pass-through.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
ec.europa.eu/home/REDACTED/.local/bin/pytest pytest tests/test_utils.py tests/test_network_processor.py tests/test_aggregation.py -v(dns block)/home/REDACTED/.local/bin/pytest pytest tests/ -v(dns block)/usr/bin/python python -(dns block)webgate.ec.europa.eu/home/REDACTED/.local/bin/pytest pytest tests/test_utils.py tests/test_network_processor.py tests/test_aggregation.py -v(dns block)/home/REDACTED/.local/bin/pytest pytest tests/ -v(dns block)/usr/bin/python python -(dns block)If you need me to access, download, or install something from one of these locations, you can either: