pandapower
pandapower copied to clipboard
[bug] merge_nets fails if net2 has additional dataframes
Bug report checklis
-
[X] Searched the issues page for similar reports
-
[X] Read the relevant sections of the documentation
-
[X] Browse the tutorials and tests for usefull code snippets and examples of use
-
[X] Reproduced the issue after updating with
pip install --upgrade pandapower
(orgit pull
) -
[X] Tried basic troubleshooting (if a bug/error) like restarting the interpreter and checking the pythonpath
Reproducible Example
# merge_nets issue minimal example
from pandapower.toolbox import merge_nets
from pandapower.networks import mv_oberrhein
from pandas import DataFrame
net = mv_oberrhein()
net2 = mv_oberrhein()
net2["example"] = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
new_net = merge_nets(net, net2, validate=False)
Issue Description and Traceback
If the second network in passed to the merge_nets function has a DataFrame that is not present within the first network the merge_nets function fails. This is because the check to determin if a DataFrame needs to be reindexed takes all DataFrames from the second network (with some exceptions e.g. key starts with _ or res_) and tries to verify that no index of net2[key] is in net[key].index but if net[key] does not exist it crashes.
Expected Behavior
OPTIONAL: A warning that a user Created DataFrame was encountered and references within might not be updated correctly. The DataFrame that is not present should be merged to the output network without issue as it does not have any overlap with the first network.
Installed Versions
- python version: 3.12
- pandas version: 2.2.1
- networkx version: 3.2.1
- scipy version: 1.12.0
- numpy version: 1.26.4
- packaging version: 24.0
- tqdm version: 4.66.2
- deepdiff version: 6.7.1
- Operating System name/version: Windows 10 Enterprise 22H2
Label
- [X] Relevant labels are selected