You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi guys, I've been using pandapower at work more often recently and found using the pandapowerNet class somewhat cumbersome, so I was wondering what the story behind it is.
From the way I was interacting with it so far, it seems to me like it could be a well defined class. Simplified, it could be something like e.g.
fromdataclassesimportdataclassimportpandasaspd@dataclassclasspandapowerNet:
bus: pd.DataFrameline: pd.DataFramedef__getitem__(self, key):
returngetattr(self, key)
def__setitem__(self, key, value):
setattr(self, key, value)
net=pandapowerNet(...)
net.bus# access as attributenet["line"] # access like a dict
From what I gather, in the current implementation the pandapowerNet is a subclass of dict (MutableMapping). Is there a reason for this? As a user, I would much rather prefer the net being a well defined type that I can rely on having certain attributes - which would also let my IDE provide proper hints, and even a little type checking on my side of the code.
One might even push it further: Analogously one might consider splitting of the results into their own classes with well defined structure instead of adding res_... tables to the original net e.g.
@dataclassclassPowerflowResult:
sucessfull: boolbus: pd.Dataframeline: pd.Dataframe# runpp could return this thingresult=pp.runpp(net)
# but also store ts in the net the way it is done right nowresult==net.result
This would be nice, but also break existing code, so the pandapowerNet would need to catch this and warn with a deprecation until it is eventually removed so net.res_<table> no longer works.
@dataclassclasspandapowerNet:
...
def__getitem__(self, key: str):
# remove eventuallyifkey.startswith("res_"):
res_table_name=key.removeprefix("res_")
print(f"deprecated, use net.result.{res_table_name} instead of net.{key}")
returngetattr(self.result, res_table_name)
returngetattr(self, key)
# remove eventuallydef__getattr__(self, name: str) ->Any:
ifname.startswith("res_"):
res_table_name=name.removeprefix("res_")
print(f"deprecated, use net.result.{res_table_name} instead of net.{name}")
returngetattr(self.result, res_table_name)
raiseAttributeError("Attribute does not exist!")
net=pandapowerNet(...)
net.res_busisnet.result.bus# same df
Analogously one might handle res_<something>_est and any other result types. I can imagine that this would be a quite huge change, but in my opinion worth it for usability in the long run.
But whatever the details might end up being, is there a plan to move pandapower to more type-able data structures in the future?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi guys, I've been using pandapower at work more often recently and found using the pandapowerNet class somewhat cumbersome, so I was wondering what the story behind it is.
From the way I was interacting with it so far, it seems to me like it could be a well defined class. Simplified, it could be something like e.g.
From what I gather, in the current implementation the pandapowerNet is a subclass of dict (MutableMapping). Is there a reason for this? As a user, I would much rather prefer the net being a well defined type that I can rely on having certain attributes - which would also let my IDE provide proper hints, and even a little type checking on my side of the code.
One might even push it further: Analogously one might consider splitting of the results into their own classes with well defined structure instead of adding
res_...tables to the original net e.g.This would be nice, but also break existing code, so the pandapowerNet would need to catch this and warn with a deprecation until it is eventually removed so
net.res_<table>no longer works.Analogously one might handle
res_<something>_estand any other result types. I can imagine that this would be a quite huge change, but in my opinion worth it for usability in the long run.But whatever the details might end up being, is there a plan to move pandapower to more type-able data structures in the future?
Beta Was this translation helpful? Give feedback.
All reactions