diff --git a/pypowsybl/network/impl/node_breaker_topology.py b/pypowsybl/network/impl/node_breaker_topology.py index 56a25e586..e06a71da1 100644 --- a/pypowsybl/network/impl/node_breaker_topology.py +++ b/pypowsybl/network/impl/node_breaker_topology.py @@ -77,7 +77,10 @@ def create_graph(self) -> _nx.Graph: Representation of the topology as a networkx graph. """ graph = _nx.Graph() - graph.add_nodes_from(self._nodes.index.tolist()) - graph.add_edges_from(self._switchs[['node1', 'node2']].values.tolist()) + for (index, row) in self.nodes.iterrows(): + graph.add_node(index, connectable_id=row['connectable_id'], connectable_type=row['connectable_type']) + for (index, row) in self._switchs.iterrows(): + graph.add_edge(row['node1'], row['node2'], id=index, name=row['name'], kind=row['kind'], + open=row['open'], retained=row['retained']) graph.add_edges_from(self._internal_connections[['node1', 'node2']].values.tolist()) return graph diff --git a/tests/test_network.py b/tests/test_network.py index 2744e26a1..fa637e655 100644 --- a/tests/test_network.py +++ b/tests/test_network.py @@ -1567,7 +1567,14 @@ def test_graph(): network_topology = n.get_node_breaker_topology('S4VL1') graph = network_topology.create_graph() assert 7 == len(graph.nodes) + assert [0, 1, 2, 3, 4, 5, 6] == list(graph.nodes) + assert {'connectable_id': 'S4VL1_BBS', 'connectable_type': 'BUSBAR_SECTION'} == graph.nodes[0] assert [(0, 5), (0, 1), (0, 3), (1, 2), (3, 4), (5, 6)] == list(graph.edges) + assert {'id': 'S4VL1_BBS_LINES3S4_DISCONNECTOR', + 'kind': 'DISCONNECTOR', + 'name': 'S4VL1_BBS_LINES3S4_DISCONNECTOR', + 'open': False, + 'retained': False} == graph.edges[0, 5] @unittest.skip("plot graph skipping")