Conversation
…mponents_from_dataframe`
…ues for nans
|
The changes described above are now implemented. As this is an API change, we should think about whether other changes in terms of better code completion/type hinting would make sense in the future. So that nothing needs to be deprecated again. Code completion/hinting could be added on two levels: To see what components exist and also what the defaults are. A couple of options (feel free to come up with anything else): EDIT: 1. Component container classfrom pypsa import components
n.add(components.Generators(), names, **kwargs) # Instance or class, see belowPros:
Cons:
2. Add classn.add.generators(names, **kwargs)Pros:
Cons:
3. Function per componentn.add_generators(names, **kwargs)Pros:
Cons:
|
|
Hi, i see this has been lying dormant. Sorry for not moving on it. Thoughts: Must-haves:
Interface: Thanks for the proposal |
|
If we are talking about api change, i also would like to try to gather everything up into objects eventually (ie. a Generators object, which holds the dataframes for static and dynamic attributes as well as adders).
But only to let it float once. Don't try to go there directly. |
|
EDIT: It might be that a |
|
Following up on this: Yes, I mean discoverability with what I called component hints. There are actually three levels of discoverability: components, component attributes and component attribute default values. With the With option 1 there are basically a couple of options on how to add components: # Old way, no deprecation needed
n.add('generators', names='gen', p_set=100)
# Mix, no attr discoverability
from pypsa.components import Generators
n.add(Generators(), names='gen', p_set=100)
# We could discuss to if passing the instance or class is the better approach here. Maybe instance if now further attributes are assigned in n.add, and class if there are assigned in there.
# Full discoverability
generators = Generators(names='gen', p_set=100)
n.add(generators)
# To get default value
print(generators.p_nom)This is only the
The issue with the But this is a second discussion and does not need to be decided right now. Now it would be great to agree on one of the options to get this PR merged. |
|
@lkstrp I really like the approach in here: # Full discoverability
generators = Generators(names='gen', p_set=100)
n.add(generators)It paves the way to the component class that @coroa mentioned. generators.defaults.p_nom such that returns the actual assigned value. |
|
Regarding defaults, isn't it simpler and less overhead to just let I move this discussion to a new issue #936 |
f3caacc to
3322b7d
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #896 +/- ##
==========================================
- Coverage 78.32% 78.28% -0.05%
==========================================
Files 22 22
Lines 4785 4799 +14
Branches 1015 1019 +4
==========================================
+ Hits 3748 3757 +9
- Misses 770 775 +5
Partials 267 267 ☔ View full report in Codecov by Sentry. |
fneum
left a comment
There was a problem hiding this comment.
I agree with most changes.
One larger issue is that the processing of indices is not consistently applied when adding multiple components at once; some of the safeguards in n.madd maybe have not been carried over.
There was a problem hiding this comment.
this is great as always @lkstrp, let me try that out locally today.
One thing I would love to see as well is a more sensible and consistent order of columns in static dataframes as well as an alignment of the orders in the timeseries dataframes' index and static dataframes' columns. I am not sure if this fits here or should be moved to another PR
| logger.warning( | ||
| "The following %s are already defined and will be skipped " | ||
| "(use overwrite=True to overwrite): %s", | ||
| n.components[cls_name]["list_name"], | ||
| ", ".join(duplicated_components), | ||
| ) |
There was a problem hiding this comment.
I think we should raise an error here instead. Like this, we give a clear feedback, logger warnings are often ignored by users according to my experience.
|
True, right now, especially when overwriting certain components, it can be inconsistent. What do you have in mind? Just hard-coded alphabetically? Or in order of when they were added? The first could be added here. The second is a bit trickier because of the two Import from Series and Import from Dataframe functions. I'd like to get rid of them at some point anyway, so it would make sense to add a consistent order then. |
|
Either alphabetically or in the order of the components_attrs/buses.csv etc. However, the latter does not include additional columns like |
Based on the attributes order in components_attrs/buses.csv has a better usability, doesn't it? It is also less of a change to the current state. I just pushed a changed for that, it is not much. I was also talking about the order of components (component names). Here alphabetical would make sense, but this will need some test rewrites as well. Or do you want to keep it as it is by last added? This just leads to issues if you overwrite components, because they are added again at the end (could also be fixed though). @FabianHofmann @fneum So I would like to get a confirmation on:
|
|
@lkstrp I like the ordering according to component_attrs it gives you more control (and we can think about better orders in the future). The only flaw it has is the |
and the efficiencies, i.e. |
|
Ok! |
n.add
Closes:
Changes proposed in this Pull Request
n.mremoveandn.addare depricated and merged inton.removeand `n.addn.import_components_from_dataframeandn.import_series_from_dataframeare deprecated (moved to internal function)Todos:
Checklist
doc.environment.yaml,environment_docs.yamlandsetup.py(if applicable).doc/release_notes.rstof the upcoming release is included.