Skip to content

Commit eff346e

Browse files
committed
rename methods
Signed-off-by: Thijs Baaijen <[email protected]>
1 parent e6712f9 commit eff346e

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

src/power_grid_model_ds/_core/model/graphs/container.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,32 @@ def empty(cls, graph_model: type[BaseGraphModel] = RustworkxGraphModel) -> "Grap
5555
complete_graph=graph_model(active_only=False),
5656
)
5757

58-
def add_branch(self, branch: BranchArray) -> None:
58+
def add_node_array(self, node_array: NodeArray) -> None:
59+
"""Add a node to all graphs"""
60+
for field in dataclasses.fields(self):
61+
graph = getattr(self, field.name)
62+
graph.add_node_array(node_array=node_array, raise_on_fail=False)
63+
setattr(self, field.name, graph)
64+
65+
def add_branch_array(self, branch_array: BranchArray) -> None:
5966
"""Add a branch to all graphs"""
6067
for field in self.graph_attributes:
6168
graph = getattr(self, field.name)
62-
graph.add_branch_array(branch_array=branch)
69+
graph.add_branch_array(branch_array=branch_array)
6370
setattr(self, field.name, graph)
6471

65-
def add_branch3(self, branch: Branch3Array) -> None:
72+
def add_branch3_array(self, branch3_array: Branch3Array) -> None:
6673
"""Add a branch to all graphs"""
6774
for field in self.graph_attributes:
6875
graph = getattr(self, field.name)
69-
graph.add_branch3_array(branch3_array=branch)
76+
graph.add_branch3_array(branch3_array=branch3_array)
77+
setattr(self, field.name, graph)
78+
79+
def delete_node(self, node: NodeArray) -> None:
80+
"""Remove a node from all graphs"""
81+
for field in dataclasses.fields(self):
82+
graph = getattr(self, field.name)
83+
graph.delete_node_array(node_array=node)
7084
setattr(self, field.name, graph)
7185

7286
def delete_branch(self, branch: BranchArray) -> None:
@@ -83,20 +97,6 @@ def delete_branch3(self, branch: Branch3Array) -> None:
8397
graph.delete_branch3_array(branch3_array=branch)
8498
setattr(self, field.name, graph)
8599

86-
def add_node(self, node: NodeArray) -> None:
87-
"""Add a node to all graphs"""
88-
for field in dataclasses.fields(self):
89-
graph = getattr(self, field.name)
90-
graph.add_node_array(node_array=node, raise_on_fail=False)
91-
setattr(self, field.name, graph)
92-
93-
def delete_node(self, node: NodeArray) -> None:
94-
"""Remove a node from all graphs"""
95-
for field in dataclasses.fields(self):
96-
graph = getattr(self, field.name)
97-
graph.delete_node_array(node_array=node)
98-
setattr(self, field.name, graph)
99-
100100
def make_active(self, branch: BranchArray) -> None:
101101
"""Add branch to all active_only graphs"""
102102

@@ -150,11 +150,10 @@ def _validate_branches(arrays: MinimalGridArrays):
150150
raise RecordDoesNotExist(f"Found invalid .to_node values in {array.__class__.__name__}")
151151

152152
def _append(self, array: FancyArray) -> None:
153+
if isinstance(array, NodeArray):
154+
self.add_node_array(array)
153155
if isinstance(array, BranchArray):
154-
self.add_branch(array)
156+
self.add_branch_array(array)
155157
if isinstance(array, Branch3Array):
156158
for record in array:
157-
self.add_branch3(record)
158-
if isinstance(array, NodeArray):
159-
for record in array:
160-
self.add_node(record)
159+
self.add_branch3_array(record)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ def append(self, array: FancyArray, check_max_id: bool = True):
200200
check_max_id (bool, optional): Whether to check if the array id is the maximum id. Defaults to True.
201201
"""
202202
self._append(array, check_max_id=check_max_id) # noqa
203-
for row in array:
204-
# pylint: disable=protected-access
205-
self.graphs._append(row)
203+
204+
# pylint: disable=protected-access
205+
self.graphs._append(array)
206206

207207
def add_branch(self, branch: BranchArray) -> None:
208208
"""Add a branch to the grid

0 commit comments

Comments
 (0)