-
Notifications
You must be signed in to change notification settings - Fork 373
Clean up column omission when columns overflow IOContext width #2087
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
Conversation
src/abstractdataframe/show.jl
Outdated
| header = displaysummary ? summary(df) : "" | ||
|
|
||
| # when allcols=true and any column overflows display, print omission message | ||
| if allcols && any(colwidths[end] .+ colwidths[1:end-1] .> displaysize(io)[2]) |
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.
when allcols=true we should disregard displaysize and just print everything if splitcols=false. What you propose should be done only if splitcols=true (splitcols=false means that the user wants to force printing everything as it is).
|
Thank you for the PR. I have left some minor comments.
For LaTeX I think when we do not display any column we should not print any rows. Do you think the same? |
I agree. I should have added more description about why I think this is ambiguous. Unlike the "text/plain" and "text/html" outputs, the "text/latex" output doesn't currently print any sort of message about omitted columns. Should I add that message, or should we just output nothing? |
I would add a message (like in HTML). Now I think you see that even simplest PRs are usually lead to many small decisions, as we have a lot of legacy code written several years ago in the package that no one touched since 😄 (and for big PRs it is even more complex as you have to also consider the whole JuliaData ecosystem). |
|
I addressed all of your notes. Specifically:
A note, the existing latex overflow is compared is against io display width, which probably isn't indicative of when an outputted table will overflow the render target. I also couldn't find a way of reasonably generating a latex table in a limited io display, so I'm not sure what situations this arises in. Regardless, I don't think this is worth trying to fix in this pull request, and probably would be more appropriately solved in PrettyTables.jl. |
|
When So I understand the logic should be:
|
|
Thanks @bkamins. I based this on the docstring as is, so let me know if the desired functionality should change. This is how it works currently, and to my understanding is the desired functionality.
The issue this stemmed from raised the |
|
Well - we have an inconsistency here in the docstrings, as https://github.com/JuliaData/DataFrames.jl/blob/master/src/abstractdataframe/show.jl#L582 says something different 😢. So this is my understanding what is a right functionality:
|
…hen allcols=false
| chunkoverflows = chunkwidths .> displaysize(io)[2] | ||
|
|
||
| if !allcols && any(chunkoverflows) | ||
| chunkedcols = chunkedcols[1:(findfirst(chunkoverflows) - 1)] |
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.
why not this and omit the next condition?
| chunkedcols = chunkedcols[1:(findfirst(chunkoverflows) - 1)] | |
| chunkedcols = chunkedcols[1:min(1, findfirst(chunkoverflows) - 1)] |
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 won't cover the case where no chunk overflows the display, but because allcols == false, only the first chunk is to be displayed anyways. I've reworked the code a bit to make it a bit clearer and will include changes in an upcoming commit.
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.
sorry I have meant min not max - fixed above.
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.
No worries, I understood what you were getting at. This still misses the case that I mentioned above.
If there's an alternative to findfirst(...) with a default value if nothing is found then we can clean this up quite a bit more, but as is we need to avoid findfirst returning nothing and throwing an error before we collapse the two conditionals.
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.
no matter if you changed it and it works. To avoid producing nothing use something(findfirst(...), the_value_you_want_on_nothing)
| will fit within the width of the REPL window, this function will return an | ||
| array of chunk column indices that should be included in each chunk. For | ||
| example, if printing is divided into two chunks containing columns 1 through 3 | ||
| and 4 through 5 respectively, `getchunkedcols` will return [[1, 2, 3], [4, 5]]. |
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.
after reviewing the code it seems that it is better to return a vector of UnitRange - this is not a big deal as this method does not have to be super efficient, but it seems cleaner to return [1:3, 4:5] in your example - for sure it will allocate less (so it would be a better style).
| │ │ Int64 │ | ||
| ├─────┼───────┤ | ||
| │ 1 │ 1 │""" | ||
| @test str == """ |
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.
It would be ideal if we had tests for all cases of combinations of allcols and splitcols and overwide column in different placements you implement (maybe we have it already, but I am just asking to be sure).
|
For the future - a standard thing to do for CI is to define column as e.g. |
|
Thanks, keep the tips coming. I got a lot to learn in the Julia space. I did take a look at your other tests using data from rand where Int64 was specified, but figured String was a pretty safe bet and the exact type isn't important for the test. |
|
@dgkf - do you have time to work on it to mark it for 1.0 release? If not it can wait |
|
I have resolved the comments I think are resolved. Three unresolved are left - could you please have a look at them. Thank you! |
|
Closing as we ended up with #2403 approach. Thank you for working on this. |
Addresses #1779
Specifically,
MIME"text/plain"allcols=trueand any column would cause the display to overflow the IOContext, prints "mxn DataFrame. Display too narrow: Omitted printing of $ncols columns"allcols=falseand no columns are displayed, only print the header (avoiding situations where all the row numbers continue to print despite all columns being omitted)MIME"text/html"searchsortedfirstMIME"text/latex"searchsortedfirstAdded Tests: