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
String attributes containing colon are not quoted #258
Comments
This was originally reported as networkx/networkx#4663 |
Thanks for reporting. This is probably very related to #118 and #224. Even though those issues are about colons in node/edge names and you are reporting about a colon in a DOT attribute value, both are DOT IDs. Not sure yet if this is a complete duplicate, though, so I suggest we keep this issue open so we can include it as another test case. All these issues should get fixed as part of the next pydot release (2.0.0) in my opinion, though be prepared that it will still be a while before that gets released. Yesterday @MaxHorwood said in #224 he would try to work on a PR. |
That's great; thanks for the update @peternowee! |
There is a workaround. One can use |
@peternowee Hope you are doing well 😄 I am still interested in finding a solution for this and it looks like you are too! Two proposals have occurred to me, and I hope you will indulge me:
I am curious if you or other contributors have proposals for how to address this. |
Accommodates behavior documented in pydot/pydot#258 which causes errors since networkx/networkx#5667.
Unfortunately, the workaround function: def _check_colon_quotes(s):
# A quick helper function to check if a string has a colon in it
# and if it is quoted properly with double quotes.
# refer https://github.com/pydot/pydot/issues/258
return ":" in s and (s[0] != '"' or s[-1] != '"') ... fails when |
@laowantong I can't follow you, where is this workaround function? I can't find in the source code. It's your own? Why not just def _check_colon_quotes(s):
# A quick helper function to check if a string has a colon in it
# and if it is quoted properly with double quotes.
# refer https://github.com/pydot/pydot/issues/258
if isinstance(s, str):
return ":" in s and (s[0] != '"' or s[-1] != '"')
else:
return False or you can use |
@horvatha Sorry, I should have made myself clearer. This is not my code, but a function of NetworkX: I am not sure how it is connected to this project though. My own workaround was to convert to string all the weights of my graph to be able to save it: def save(self, stem_or_path):
# workaround for https://github.com/pydot/pydot/issues/258#issuecomment-1276492779.
# Convert all edges attributes to strings.
# The same should be done for nodes attributes, but YAGNI.
G = deepcopy(self)
for (x, y, data) in G.edges(data=True):
for (k, v) in list(data.items()):
G[x][y][k] = str(v)
smart_path(stem_or_path).write_text(nx.nx_pydot.to_pydot(G).to_string()) |
Issue documented in pydot/pydot#258 (comment) Fixes #5.
Honestly, IMHO the right fix is to simply ensure that values are quoted by pydot whenever they need to be. I see this still isn't fixed, looks like |
Seen:
Expected:
(
dot
won't compile without the value being quoted, complaining ofError: file.dot: syntax error in line x near ':'
)This behavior has been confirmed on pydot 2.0.0.dev0.
The text was updated successfully, but these errors were encountered: