Introduce data validation (pydantic/ pandera) and dynamic attribute handling#1128
Closed
lkstrp wants to merge 2 commits intoPyPSA:masterfrom
Closed
Introduce data validation (pydantic/ pandera) and dynamic attribute handling#1128lkstrp wants to merge 2 commits intoPyPSA:masterfrom
pydantic/ pandera) and dynamic attribute handling#1128lkstrp wants to merge 2 commits intoPyPSA:masterfrom
Conversation
8 tasks
Contributor
|
This is awesome! The improvements far outweigh the breaking changes. In particular looking at the potential extensions in the long-term. Let me know when I should scroll through the code |
4 tasks
This was referenced Dec 10, 2025
4 tasks
Member
Author
|
Closed with ref to #1487 |
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.
Closes #348
Closes #722
Closes #734
Changes proposed in this Pull Request
Summary
c.dynamicandc.staticData Validation
Componentsclass/ subclasses andComponentType. The plan is to bring it to theNetworkclass as well, when it is split into data and logic with some refactoring.pypsa/data/component_attrs/, which has some changed structure now.check_consistency.Dynamic Attributes
Dynamic Attribute Initialisation
required: Likenameetc. These must be set by the user and cannot have a default value.configurable: These can be set by the user. If not, the default value is used.optional: These can be set by the user. If not set, they have no effect on the optimisation. Therefore, no default value must be applied and they are not even added.outputand a fifth typecustomfor all attributes that are manually defined and only used in the extra functionality.Ambiguity of static or dynamic attributes
c.dynamic, but the column still existed inn.staticfor both dynamic and static components. The data for dynamic components in n.static was simply unused and misleading.n.dynamicorn.static. Attributes in both containers are now mutually exclusive.c.dynamicno longer shows only the dynamic values. Which could be solved with the introduced DynamicDataStore, which is a dictionary with some more functionality.c.dynamicis now an empty dict-like store by default. For backwards compatibility, instead of anAttributeErroryou can still get an empty dynamic df (as was possible before) with a small warning. I am thinking of adding similar functionality for the static data.naninstead of"".""was used. This led to some boilerplate and also some bugs (where empty""components existed). The above data validation allows to easily enforce and usenaninstead.Breaking
Some of those changes need to be breaking:
naninstead of"": This can't be handled and needs a big note. I don't know how many users build logic on top of that. But fixing this is fine, but maybe not to trivial.n.components.generators.attrs: Also not backwards compatible. But I don't think too many users are using this and a fix is trivial.Dynamic Attribute andling
@fneum @FabianHofmann @coroa
This is still a draft, so there is no need to review any code yet. While most things have already been discussed, I would mainly like feedback on the general concepts and the introduced breaking things.
This PR is a bit bloated again and data validation was not even planned for
1.0. Let's say I fell into a rabbit hole. But I think it is easier to make these changes all at once. Instead of spending too much time pointing people to new and new deprecations and adding those things one by one. Not sure if there is anything else on the "would be nice but also breaks things" list that could be added.Checklist
doc.doc/release_notes.rstof the upcoming release is included.