-
Notifications
You must be signed in to change notification settings - Fork 59
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
fix print_tree and add test #42
fix print_tree and add test #42
Conversation
Codecov Report
@@ Coverage Diff @@
## master #42 +/- ##
=========================================
Coverage ? 57.64%
=========================================
Files ? 3
Lines ? 314
Branches ? 0
=========================================
Hits ? 181
Misses ? 133
Partials ? 0
Continue to review full report at Codecov.
|
Example 1
prints
Example 2
prints
|
Since this has a test I'm inclined to go with this version. Should we consider adding a line |
I have use cases of the 'print_tree' function where it creates a text summary report about a dataset, whose underlying tree structure may be confusing for the person who reads the report. I would be slightly annoyed if I had to remove the "tree truncated" line if I don't want it in the output.
|
Totally understood re the annoyance. This is a bit tricky. Julia truncates arrays and other containers when they get too big; in general there seems to be a pretty strong commitment to avoid "endless printing." So following that model seems useful here. But then I think we need some visual indicator of truncation (e.g., arrays use ellipses), at least in the case where the user hasn't explicitly provided What if we change the default value for print_warning_if_trunc = false
if maxdepth === nothing
maxdepth = 5
print_warning_if_trunc = true
end Ellipses are of course an alternative to printing a warning at the end. I'm just keying off your comment #38 (comment), plus the fact that if you've explicitly asked for a certain depth you might want to omit the ellipses. |
This was more tricky than I anticipated, as the Consider therefore this implementation which indicate truncation with a single vertical ellipsis under final node if Ex1ellipsis if default maxdepth and depth > maxdepth
prints
Ex2no ellipsis if default maxdepth and depth < maxdepth
Ex3no ellipsis if maxdepth set
prints
@timholy @ericphanson if you agree to this, I can add some more test which covers the above mentioned cases. |
I'm extremely happy with this! I suspect you could solve the recursive problem by adding a keyword argument Tests of your improved behavior would indeed be nice. |
Good to hear. I'll await @ericphanson comments, as I'm hijacking his pr. Regarding the |
One possible way: if |
Thanks for pinging me on this :). I think this solution would not be optimal for my use case, namely using However, we've already vendored We may have another reason to stick to a vendored copy of the function, which is that I sometimes saw somewhat strange errors when trying out variants of Convex#325 locally, I think which may be related to #15. That makes me think it's probably safer for us to keep the function vendored, because I fear our So in all, such a change wouldn't support my the case I created the other PR for, but that's okay and we can just keep our vendored copy. I do personally have a preference for always printing ellipses if something is truncated because I think it helps avoid confusion. One idea is |
I've incorporated a couple of tests for the new implementation of the different cases.
The return value approach sounds obvious in hindsight. Thanks.
Great!
In the current implementation you can force printing of ellispes by |
It seems like I broke the build on Julia 0.7 build. Test docstrings apparently, and out of sync with master runtests.jl |
Have fixed some tests and added to the documentation string. I changed my mind on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is lovely and basically ready to merge. One small comment re documentation or behavior.
value can be overriden by the `maxdepth` parameter. The charset to use in | ||
value can be overriden by the `maxdepth` parameter. Nodes that are truncated are | ||
indicated by a vertical ellipsis below the truncated node, this indication can be | ||
turned off by providing `indicate_truncation=false` as a kwarg. The charset to use in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the current implementation you have to provide a non-default value for maxdepth
too:
julia> print_tree(SingleChildInfiniteDepth(); indicate_truncation=false)
SingleChildInfiniteDepth()
└─ SingleChildInfiniteDepth()
└─ SingleChildInfiniteDepth()
└─ SingleChildInfiniteDepth()
└─ SingleChildInfiniteDepth()
└─ SingleChildInfiniteDepth()
⋮
but
julia> print_tree(SingleChildInfiniteDepth(), 5; indicate_truncation=false)
SingleChildInfiniteDepth()
└─ SingleChildInfiniteDepth()
└─ SingleChildInfiniteDepth()
└─ SingleChildInfiniteDepth()
└─ SingleChildInfiniteDepth()
└─ SingleChildInfiniteDepth()
Worth mentioning this? Or should we change the behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. We should change the behavior, and I just did. indicate_truncation
should now work as expected, regardless of maxdepth
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also removed the whole maxdepth=nothing
business as it is no longer needed.
Thanks for a great contribution! New release coming... |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #42 +/- ##
==========================================
+ Coverage 57.00% 57.64% +0.64%
==========================================
Files 3 3
Lines 307 314 +7
==========================================
+ Hits 175 181 +6
- Misses 132 133 +1 ☔ View full report in Codecov by Sentry. |
fix behaviour of maxdepth argument to print_tree