Skip to content

Commit 7fffdef

Browse files
committed
fix bug in delete node
1 parent 201c972 commit 7fffdef

File tree

1 file changed

+13
-8
lines changed
  • src/compas/datastructures/network/core

1 file changed

+13
-8
lines changed

src/compas/datastructures/network/core/graph.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,12 @@ def delete_node(self, key):
467467
>>>
468468
469469
"""
470-
del self.edge[key]
471-
del self.adjacency[key]
472-
del self.node[key]
470+
if key in self.edge:
471+
del self.edge[key]
472+
if key in self.adjacency:
473+
del self.adjacency[key]
474+
if key in self.node:
475+
del self.node[key]
473476
for u in list(self.edge):
474477
for v in list(self.edge[u]):
475478
if v == key:
@@ -525,8 +528,8 @@ def summary(self):
525528
-------
526529
str
527530
"""
528-
tpl = "\n".join(["Graph summary", "============", "- nodes: {}", "- edges: {}"])
529-
return tpl.format(self.number_of_nodes(), self.number_of_edges())
531+
tpl = "\n".join(["{} summary", "=" * (len(self.name) + len(" summary")), "- nodes: {}", "- edges: {}"])
532+
return tpl.format(self.name, self.number_of_nodes(), self.number_of_edges())
530533

531534
def number_of_nodes(self):
532535
"""Compute the number of nodes of the network.
@@ -567,9 +570,11 @@ def nodes(self, data=False):
567570
2-tuple
568571
The next node as a (key, attr) tuple, if ``data`` is ``True``.
569572
"""
570-
if data:
571-
return iter(self.node.items())
572-
return iter(self.node)
573+
for key in self.node:
574+
if not data:
575+
yield key
576+
else:
577+
yield key, self.node_attributes(key)
573578

574579
def nodes_where(self, conditions, data=False):
575580
"""Get nodes for which a certain condition or set of conditions is true.

0 commit comments

Comments
 (0)