Skip to content

Commit df4bb3f

Browse files
committed
make substation_nodes optional
1 parent a134aa9 commit df4bb3f

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/power_grid_model_ds/_core/model/graphs/models/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ def get_all_paths(self, ext_start_node_id: int, ext_end_node_id: int) -> list[li
248248

249249
return [self._internals_to_externals(path) for path in internal_paths]
250250

251-
def get_components(self, substation_nodes: list[int]) -> list[list[int]]:
251+
def get_components(self, substation_nodes: list[int] | None = None) -> list[list[int]]:
252252
"""Returns all separate components when the substation_nodes are removed of the graph as lists"""
253-
if len(substation_nodes):
253+
if substation_nodes:
254254
warnings.warn(
255255
message="""
256256
get_components: substation_nodes argument is deprecated and will be removed in a future release.
@@ -262,6 +262,7 @@ def get_components(self, substation_nodes: list[int]) -> list[list[int]]:
262262
category=DeprecationWarning,
263263
stacklevel=2,
264264
)
265+
substation_nodes = substation_nodes or []
265266
with self.tmp_remove_nodes(substation_nodes):
266267
internal_components = self._get_components()
267268
return [self._internals_to_externals(component) for component in internal_components]

src/power_grid_model_ds/_core/model/grids/helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ def set_feeder_ids(grid: "Grid"):
4646
"""
4747
_reset_feeder_ids(grid)
4848
feeder_node_ids = grid.node.filter(node_type=NodeType.SUBSTATION_NODE)["id"]
49-
components = grid.graphs.active_graph.get_components(feeder_node_ids)
49+
with grid.graphs.active_graph.tmp_remove_nodes(feeder_node_ids):
50+
components = grid.graphs.active_graph.get_components()
5051
for component_node_ids in components:
5152
component_branches = _get_active_component_branches(grid, component_node_ids)
5253

tests/unit/model/grids/test_grid_search.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ def test_get_branches_in_path_empty_path(self, basic_grid):
5757

5858

5959
def test_component_three_winding_transformer(grid_with_3wt):
60-
component_list = grid_with_3wt.graphs.active_graph.get_components(
61-
grid_with_3wt.node.filter(node_type=NodeType.SUBSTATION_NODE.value).id
62-
)
60+
substation_nodes = grid_with_3wt.node.filter(node_type=NodeType.SUBSTATION_NODE.value).id
61+
with grid_with_3wt.graphs.active_graph.tmp_remove_nodes(substation_nodes):
62+
component_list = grid_with_3wt.graphs.active_graph.get_components()
6363

6464
# check the components are as expected
6565
# use sets to make sure the order of the components is not important

0 commit comments

Comments
 (0)