Skip to content

Commit 7c6b42b

Browse files
committed
Fix: prevent type change in graph.external_ids when using tmp_remove_nodes_array
Signed-off-by: Thijs Baaijen <[email protected]>
1 parent df324f4 commit 7c6b42b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def tmp_remove_nodes(self, nodes: list[int]) -> Generator:
208208
yield
209209

210210
for node in nodes:
211-
self.add_node(node)
211+
self.add_node(int(node)) # convert to int to avoid type issues when input is e.g. a numpy array
212212
for source, target in edge_list:
213213
self.add_branch(source, target)
214214

tests/unit/model/graphs/test_graph_model.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ def test_tmp_remove_nodes(graph_with_2_routes: BaseGraphModel) -> None:
171171
assert counter_before == counter_after
172172

173173

174+
def test_tmp_remove_nodes_array_input(graph_with_2_routes: BaseGraphModel) -> None:
175+
with graph_with_2_routes.tmp_remove_nodes(np.array([1, 2])): # type: ignore[arg-type]
176+
pass
177+
178+
# check that the external ids are still all integers instead of e.g. np.int
179+
assert all([isinstance(e_id, int) for e_id in graph_with_2_routes.external_ids])
180+
181+
174182
def test_get_components(graph_with_2_routes: BaseGraphModel):
175183
graph = graph_with_2_routes
176184
graph.add_node(99)

0 commit comments

Comments
 (0)