Remove all nodes and edges from the graph. This also removes the name, and all graph, node, and edge attributes. Examples -------- >>> G = nx.path_graph(4) # or DiGraph >>> G.clear() >>> list(G.nodes) [] >>> list(G.edges) []
(self)
| 1505 | return DegreeView(self) |
| 1506 | |
| 1507 | def clear(self): |
| 1508 | """Remove all nodes and edges from the graph. |
| 1509 | |
| 1510 | This also removes the name, and all graph, node, and edge attributes. |
| 1511 | |
| 1512 | Examples |
| 1513 | -------- |
| 1514 | >>> G = nx.path_graph(4) # or DiGraph |
| 1515 | >>> G.clear() |
| 1516 | >>> list(G.nodes) |
| 1517 | [] |
| 1518 | >>> list(G.edges) |
| 1519 | [] |
| 1520 | |
| 1521 | """ |
| 1522 | if self._graph_type == graph_def_pb2.ARROW_PROPERTY: |
| 1523 | # create an empty graph, no need to convert arrow to dynamic |
| 1524 | self._graph_type = graph_def_pb2.DYNAMIC_PROPERTY |
| 1525 | graph_def = init_empty_graph_in_engine( |
| 1526 | self, self.is_directed(), self._distributed |
| 1527 | ) |
| 1528 | self._key = graph_def.key |
| 1529 | else: |
| 1530 | op = dag_utils.clear_graph(self) |
| 1531 | op.eval() |
| 1532 | |
| 1533 | self.graph.clear() |
| 1534 | self.schema.clear() |
| 1535 | self._add_node_cache.clear() |
| 1536 | self._add_edge_cache.clear() |
| 1537 | self._remove_node_cache.clear() |
| 1538 | self._remove_edge_cache.clear() |
| 1539 | self.cache.clear() |
| 1540 | |
| 1541 | @clear_mutation_cache |
| 1542 | def clear_edges(self): |
nothing calls this directly
no test coverage detected