Skip to content

Commit

Permalink
in nx_node_integer_mapping, do not modify the provided graph
Browse files Browse the repository at this point in the history
Currently, the graph passed to the function is modified. Seems dangerous, in particular since we return a graph anyway.
  • Loading branch information
Yquetzal authored Jul 8, 2024
1 parent 74d55d3 commit e5999b0
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions cdlib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <numeric_id, original_node_label>, false otherwise
"""

convert = False
for nid in graph.nodes():
if isinstance(nid, str):
Expand All @@ -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")

Expand Down

0 comments on commit e5999b0

Please sign in to comment.