Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3
1.4
28 changes: 0 additions & 28 deletions src/power_grid_model_ds/_core/model/graphs/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"""Stores the GraphContainer class"""

import dataclasses
import warnings
from dataclasses import dataclass
from typing import TYPE_CHECKING, Generator

Expand Down Expand Up @@ -63,45 +62,18 @@ def add_node_array(self, node_array: NodeArray) -> None:
graph = getattr(self, field.name)
graph.add_node_array(node_array=node_array, raise_on_fail=False)

def add_node(self, node: NodeArray) -> None:
"""Add a node to all graphs"""
warnings.warn(
"add_node is deprecated and will be removed in a future release, use add_node_array instead",
category=DeprecationWarning,
stacklevel=2,
)
self.add_node_array(node_array=node)

def add_branch_array(self, branch_array: BranchArray) -> None:
"""Add a branch to all graphs"""
for field in self.graph_attributes:
graph = getattr(self, field.name)
graph.add_branch_array(branch_array=branch_array)

def add_branch(self, branch: BranchArray) -> None:
"""Add a branch to all graphs"""
warnings.warn(
"add_branch is deprecated and will be removed in a future release, use add_branch_array instead",
category=DeprecationWarning,
stacklevel=2,
)
self.add_branch_array(branch_array=branch)

def add_branch3_array(self, branch3_array: Branch3Array) -> None:
"""Add a branch to all graphs"""
for field in self.graph_attributes:
graph = getattr(self, field.name)
graph.add_branch3_array(branch3_array=branch3_array)

def add_branch3(self, branch: Branch3Array) -> None:
"""Add a branch to all graphs"""
warnings.warn(
"add_branch3 is deprecated and will be removed in a future release, use add_branch3_array instead",
category=DeprecationWarning,
stacklevel=2,
)
self.add_branch3_array(branch3_array=branch)

def delete_node(self, node: NodeArray) -> None:
"""Remove a node from all graphs"""
for field in dataclasses.fields(self):
Expand Down
29 changes: 11 additions & 18 deletions src/power_grid_model_ds/_core/model/graphs/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# SPDX-License-Identifier: MPL-2.0

import warnings
from abc import ABC, abstractmethod
from contextlib import contextmanager
from typing import TYPE_CHECKING, Generator
Expand Down Expand Up @@ -253,23 +252,17 @@ def get_all_paths(self, ext_start_node_id: int, ext_end_node_id: int) -> list[li

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

def get_components(self, substation_nodes: list[int] | None = None) -> list[list[int]]:
"""Returns all separate components when the substation_nodes are removed of the graph as lists"""
if substation_nodes:
warnings.warn(
message="""
get_components: substation_nodes argument is deprecated and will be removed in a future release.
The functionality is still available with the use of the `tmp_remove_nodes` context manager.

Example:
>>> with graph.tmp_remove_nodes(substation_nodes):
>>> components = graph.get_components()
""",
category=DeprecationWarning,
stacklevel=2,
)
with self.tmp_remove_nodes(substation_nodes or []):
internal_components = self._get_components()
def get_components(self) -> list[list[int]]:
"""Returns all separate components when the substation_nodes are removed of the graph as lists

If you want to get the components of the graph without certain nodes,
use the `tmp_remove_nodes` context manager.

Example:
>>> with graph.tmp_remove_nodes(substation_nodes):
>>> components = graph.get_components()
"""
internal_components = self._get_components()
return [self._internals_to_externals(component) for component in internal_components]

def get_connected(
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/model/graphs/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def graph_container_with_5_nodes():
for node_id in range(1, 6):
node = NodeArray.empty(1)
node.id = node_id
graph_container.add_node(node)
graph_container.add_node_array(node)
return graph_container


Expand All @@ -53,7 +53,7 @@ def three_winding_transformers():
def test_add_branch3(
graph_container_with_5_nodes: GraphContainer, three_winding_transformers: ThreeWindingTransformerArray
):
graph_container_with_5_nodes.add_branch3(three_winding_transformers)
graph_container_with_5_nodes.add_branch3_array(three_winding_transformers)
for from_node, to_node in [(1, 2), (1, 4), (1, 5), (4, 5)]:
assert graph_container_with_5_nodes.active_graph.has_branch(from_node, to_node)
assert graph_container_with_5_nodes.complete_graph.has_branch(from_node, to_node)
Expand All @@ -66,7 +66,7 @@ def test_add_branch3(
def test_delete_branch3(
graph_container_with_5_nodes: GraphContainer, three_winding_transformers: ThreeWindingTransformerArray
):
graph_container_with_5_nodes.add_branch3(three_winding_transformers)
graph_container_with_5_nodes.add_branch3_array(three_winding_transformers)
graph_container_with_5_nodes.delete_branch3(three_winding_transformers[0])

assert not graph_container_with_5_nodes.active_graph.has_branch(1, 2)
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/model/graphs/test_graph_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,14 @@ def test_get_components(graph_with_2_routes: BaseGraphModel):
assert set(components[2]) == {100}


def test_get_components_with_substation_nodes(graph_with_2_routes):
def test_get_components_with_tmp_removed_substation_nodes(graph_with_2_routes):
graph = graph_with_2_routes
graph.add_node(99)
graph.add_branch(1, 99)
substation_nodes = np.array([1])

components = graph.get_components(substation_nodes=substation_nodes)
with graph.tmp_remove_nodes(substation_nodes):
components = graph.get_components()

assert len(components) == 3
assert set(components[0]) == {2, 3}
Expand Down
Loading