diff options
author | Shaked Brody <shakedbr@gmail.com> | 2022-06-23 18:39:54 +0300 |
---|---|---|
committer | Jarrod Millman <jarrod.millman@gmail.com> | 2022-07-18 11:36:27 -0700 |
commit | a29fc1c2754df39ba4836ac4bedb0385f256e432 (patch) | |
tree | 3d3cbe2a97c497c5b232ee7b63b2fca580716532 | |
parent | 228ccd7862051ceb81a44396bf1ffc7022c269f2 (diff) | |
download | networkx-a29fc1c2754df39ba4836ac4bedb0385f256e432.tar.gz |
Fix pydot colon check node-to-str conversion (#5809)
-rw-r--r-- | networkx/drawing/nx_pydot.py | 6 | ||||
-rw-r--r-- | networkx/drawing/tests/test_pydot.py | 13 |
2 files changed, 16 insertions, 3 deletions
diff --git a/networkx/drawing/nx_pydot.py b/networkx/drawing/nx_pydot.py index 2b01f59f..2055eb32 100644 --- a/networkx/drawing/nx_pydot.py +++ b/networkx/drawing/nx_pydot.py @@ -432,15 +432,15 @@ def pydot_layout(G, prog="neato", root=None): node_pos = {} for n in G.nodes(): - n = str(n) + str_n = str(n) # Explicitly catch nodes with ":" in node names or nodedata. - if _check_colon_quotes(n): + if _check_colon_quotes(str_n): raise ValueError( f'Node names and node attributes should not contain ":" unless they are quoted with "".\ For example the string \'attribute:data1\' should be written as \'"attribute:data1"\'.\ Please refer https://github.com/pydot/pydot/issues/258' ) - pydot_node = pydot.Node(n).get_name() + pydot_node = pydot.Node(str_n).get_name() node = Q.get_node(pydot_node) if isinstance(node, list): diff --git a/networkx/drawing/tests/test_pydot.py b/networkx/drawing/tests/test_pydot.py index 2e5e3ec6..90d025e2 100644 --- a/networkx/drawing/tests/test_pydot.py +++ b/networkx/drawing/tests/test_pydot.py @@ -175,3 +175,16 @@ def test_hashable_pydot(graph_type): assert {str(i) for i in G.nodes()} == set( nx.nx_pydot.from_pydot(nx.nx_pydot.to_pydot(G)).nodes ) + + +def test_pydot_numrical_name(): + G = nx.Graph() + G.add_edges_from([("A", "B"), (0, 1)]) + graph_layout = nx.nx_pydot.pydot_layout(G, prog="dot") + assert isinstance(graph_layout, dict) + assert "0" not in graph_layout + assert 0 in graph_layout + assert "1" not in graph_layout + assert 1 in graph_layout + assert "A" in graph_layout + assert "B" in graph_layout |