From e5999b036b1172c12e6998c9a172d3a23d99ecd0 Mon Sep 17 00:00:00 2001 From: Cazabet Remy Date: Mon, 8 Jul 2024 10:40:47 +0200 Subject: [PATCH] in nx_node_integer_mapping, do not modify the provided graph Currently, the graph passed to the function is modified. Seems dangerous, in particular since we return a graph anyway. --- cdlib/utils.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cdlib/utils.py b/cdlib/utils.py index 17a6e03..f678315 100644 --- a/cdlib/utils.py +++ b/cdlib/utils.py @@ -201,7 +201,6 @@ def nx_node_integer_mapping(graph: object) -> tuple: :param graph: networkx graph :return: if the node labels are string: networkx graph, dictionary , false otherwise """ - convert = False for nid in graph.nodes(): if isinstance(nid, str): @@ -216,8 +215,8 @@ def nx_node_integer_mapping(graph: object) -> tuple: node_map[nid] = name label_map[name] = nid - nx.relabel_nodes(graph, label_map, copy=False) - return graph, node_map + graph_copy = nx.relabel_nodes(graph, label_map, copy=True) + return graph_copy, node_map else: raise ValueError("graph must be a networkx Graph object")