FIX escape double quotes when exporting tree with Graphviz#17575
Merged
Conversation
20ebf08 to
7677fe3
Compare
ogrisel
reviewed
Jun 12, 2020
| '2 [label="gini = 0.0\\nsamples = 3\\nvalue = [0, 3]"] ;\n' \ | ||
| '0 -> 2 [labeldistance=2.5, labelangle=-45, ' \ | ||
| 'headlabel="False"] ;\n' \ | ||
| '}' |
Member
There was a problem hiding this comment.
To improve readability may I suggest the following idiom:
from textwrap import dedent
...
contents1 = export_graphviz(clf,
feature_names=["feature\"0\"", "feature\"1\""],
out_file=None)
contents2 = dedent("""\
digraph Tree {
node [shape=box] ;
...
}""")
Contributor
Author
There was a problem hiding this comment.
I was hesitant to use a convention different from the surrounding code, since all test cases in the file use this form. Do you think it's worth changing only for this new case?
Contributor
Author
There was a problem hiding this comment.
@ogrisel So would you prefer the code using the same convention as the surrounding test cases? Or the one you suggested?
Double quotes in graphviz labels need escaping. Escape class and feature names to avoid breaking the result.
glemaitre
approved these changes
May 21, 2024
glemaitre
left a comment
Member
There was a problem hiding this comment.
I think this fix make sense. I added an entry in what's new and solve the failure in tests due to changes that have been merged in between regarding the font style.
adrinjalali
approved these changes
Oct 22, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reference Issues/PRs
What does this implement/fix? Explain your changes.
Double quotes in graphviz labels need escaping. Escape class and feature
names to avoid breaking the result.
Any other comments?