Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in nx_node_integer_mapping, do not modify the provided graph but return a copy #244

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading