fix: resolve ignored individual NUTS level configurations - #2210
Open
stan-buren wants to merge 3 commits into
Open
fix: resolve ignored individual NUTS level configurations#2210stan-buren wants to merge 3 commits into
stan-buren wants to merge 3 commits into
Conversation
Fixes PyPSA#2207. Individual country overrides in clustering.administrative.countries were silently ignored because the script filtered admin_levels at the root level instead of parsing the nested 'countries' dictionary. - Update dict comprehension in base_network.py and cluster_network.py to extract country levels from nested 'countries' config - Add unit and regression tests covering overrides extraction, key leaks, and edge cases - Update release notes
for more information, see https://pre-commit.ci
Contributor
Author
|
I've extracted the country NUTS level extraction logic into a shared helper function I also updated the tests to import this helper directly, removed the local duplicate definition, and cleaned up the redundant regression test that contained a copy of the old buggy comprehension. |
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 #2207. Individual country overrides in clustering.administrative.countries were silently ignored because the script filtered admin_levels at the root level instead of parsing the nested 'countries' dictionary.
Closes #2207.
Changes proposed in this Pull Request
Problem & Root Cause
PyPSA-Eur allows users to define custom NUTS levels for specific countries (e.g.
countries: {'DE': 2}) in their configuration file underclustering.administrative.countries. During configuration loading and validation, this config is parsed into a dict (admin_levels) containing the keys"level"and"countries", where"countries"holds the nested dictionary with per-country levels.Previously,
scripts/base_network.pyandscripts/cluster_network.pyparsed this using:When iterating over
admin_levels.items(), the keykis either"level"or"countries". The condition(k in countries)evaluates whether the string"countries"matches any of the active country codes (e.g.,["DE", "FR"]), which always returnsFalse. As a result, thecountry_leveldict was silently created as an empty dict{}and all user-defined per-country overrides were silently ignored.Solution
scripts/base_network.pyandscripts/cluster_network.pyto:"countries"dictionary and filters keys based on the active countries list.All 6 unit tests pass successfully locally.
Checklist
Required:
doc/release_notes.md.If applicable:
scripts/lib/validation.doc/*.mdfiles.