Skip to content

Commit

Permalink
Fix crash when creating a feeder bay using an empty dataframe (#755)
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
  • Loading branch information
geofjamg authored Jun 4, 2024
1 parent 3f2e911 commit d0eb810
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ public List<List<SeriesMetadata>> getMetadata(DataframeElementType elementType)

@Override
public void applyModification(Network network, List<UpdatingDataframe> dataframes, boolean throwException, ReportNode reportNode) {
PyPowsyblApiHeader.ElementType elementType = PyPowsyblApiHeader.ElementType.valueOf(dataframes.get(0).getStrings("feeder_type").get(0));
DataframeElementType type = convert(elementType);
NetworkElementAdders.addElementsWithBay(type, network, dataframes, throwException, reportNode);
UpdatingDataframe firstUpdatingDataframe = dataframes.get(0);
if (firstUpdatingDataframe.getRowCount() > 0) {
PyPowsyblApiHeader.ElementType elementType = PyPowsyblApiHeader.ElementType.valueOf(firstUpdatingDataframe.getStrings("feeder_type").get(0));
DataframeElementType type = convert(elementType);
NetworkElementAdders.addElementsWithBay(type, network, dataframes, throwException, reportNode);
}
}
}
10 changes: 7 additions & 3 deletions tests/test_network_modification.py
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,10 @@ def test_exception_create_element_with_bay():
assert exc.match('Bus or busbar section S1VL2_BBS not found')





def test_empty_load_bay_segv():
n = pp.network.create_four_substations_node_breaker_network()
assert len(n.get_loads()) == 6
df = pd.DataFrame(index=[], columns=["id", "p0", "q0", "bus_or_busbar_section_id", "position_order"],
data=[])
pp.network.create_load_bay(network=n, df=df, raise_exception=True)
assert len(n.get_loads()) == 6 # no crash and no network change

0 comments on commit d0eb810

Please sign in to comment.