8000 Long node names get mangled by `create_dot` · Issue #483 · pydot/pydot · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Long node names get mangled by create_dot #483

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

Open
Peiffap opened this issue May 30, 2025 · 2 comments · May be fixed by #486
Open

Long node names get mangled by create_dot #483

Peiffap opened this issue May 30, 2025 · 2 comments · May be fixed by #486

Comments

@Peiffap
Copy link
Peiffap commented May 30, 2025

Originally reported by @dougthor42 in networkx/networkx#7648.

When working with long node names (~ >130 characters), create_dot mangles the name by adding line breaks. This makes it hard to round-trip pydot.Graph objects through the dot command and read them back in again (which is what nx.nx_pydot.pydot_layout does).

A minimum reproduction is

>>> import networkx as nx
>>> import pydot
>>> import locale
>>> G = nx.Graph()
>>> G.add_node("=10chars= " * 14)
>>> P = nx.nx_pydot.to_pydot(G)
>>> bytes = P.create_dot()
>>> D = str(bytes, encoding=locale.getpreferredencoding())
>>> Q = pydot.graph_from_dot_data(D)[0]
>>> print(Q.get_nodes()[-1].get_name())
"=10chars= =10chars= =10chars= =10chars= =10chars= =10chars= =10chars= =10chars= =10chars= =10chars= =10chars= =10chars= =10chars= =\
10chars= "
>>> print(pydot.quote_id_if_necessary(str(list(G.nodes())[0])))
"=10chars= =10chars= =10chars= =10chars= =10chars= =10chars= =10chars= =10chars= =10chars= =10chars= =10chars= =10chars= =10chars= =10chars= "

The two names aren't equal, and it would be nice if they were.

@lkk7
Copy link
Member
lkk7 commented Jun 1, 2025

(Continuing the discussion from #420)
(BTW, that PR doesn't fix the issue)

It's Graphviz (dot) itself that performs the name splitting, not pydot.

I couldn't find any documentation mentioning this. If this is an old, deeply ingrained thing, then they'll never change it. I understand it's probably for visual clarity, but still... 😞

I'm wondering what's the expected behavior of pydot in this situation.

I don't think we should:

  • Remove the split when reading an already split graph (because someone might be doing it intentionally)
  • Do that split anywhere in the internal representation (because it's undocumented, weird, and unexpected)

The least invasive way to fix the problem might be to extend get_node so that it also checks the "unsplit" names of existing nodes.

CC: @ferdnyc

@lkk7 lkk7 linked a pull request Jun 1, 2025 that will close this issue
@lkk7
Copy link
Member
lkk7 commented Jun 1, 2025

Proposed fix: #486
(tired of mypy complaining, but ignore that because everything else passes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0