-
Notifications
You must be signed in to change notification settings - Fork 38
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
Array-like output #18
Comments
Hi @bkamins! I thought about this when I added the option to crop so that the print fits the display. I got stuck in cases when the combined size of the first and last row is bigger than the display size. This can happen when the table has big strings. In this case, I do not know what to do. Any tips? |
I was thinking about it also. Base is not ideal (check out this What I would do is the following set of rules:
(in steps 2 and 3 there is no recursion as they can work only from one side - only step 1 is recursive) EDIT: of course you need to reserve space in the middle for Also note that currently (as is) you do not handle this case in the best way possible (I am on a terminal with 166 characters width-wise):
nor this one
(both these have to be fixed before the algorithm described above could work) Is my idea clear? |
If this was done and (sorry for the laundry list of wishes 😄 - I hope it is OK):
then I would love to switch DataFrames.jl default display to your package and avoid duplicating the efforts (actually |
Nice! I think I understood what you want. This would be a major change in the way I tried to handle cropping, but it is possible! Let's see what I can do :)
That's fine! Thanks for all those comments and suggestions :)
I always wanted it. This will require some major changes in the way I print things to add the capability to change the backend between plain text, HTML, and LaTeX. Maybe I will need some help (I am not HTML expert) but I think I can do this.
In this case, I have absolutely no experience. Can you give me some help about how can I start to debug what is making the load time high?
Perfect! I will do my best to add those features :) |
It is only a suggestion, but simply the way Base works here is almost perfect IMO (except for the corner case I have mentioned)
Actually this is even simpler than plain text (you simply have to add markups). You can have a look at these test files for examples: https://github.com/JuliaData/DataFrames.jl/blob/master/test/io.jl. The only tricky part is getting device dimensions, see the note here about environment variables.
This is pretty tricky as it best should be debugged under Win, Linux and OSx as there are some differences in load times (Win tends to be slowest). The general idea is to drop a dependency if it adds a significant load time while not being used very much in the package. For example Parameters.jl is an awesome package, but it seems you use it in only three places. I have not benchmarked how much would be saved by removing it, but its "stand alone" load time is 0.127939 seconds, which is 25% of the total load time of your package. But this requirement was rather a wish - it is likely that package load times improve in the future. Thank you for taking time of looking into it. Also you might consider to have a look at |
Just an update! I need to finish other projects due to some demands at work, but I reviewed the code of PrettyTables and I have at least a plan to implement everything asked here. I hope I will manage to find time to do this soon :) The idea is to make the printing function do not print per se, but call printing functions from backends. Then, we can have HTML, LaTeX, etc. |
Great - this "decoupling" of a backend is exactly what I think is needed, just like for plotting. The only thing to have in the consideration is that different backends might accept different configuration options (e.g. LaTeX has a finite size of page), HTML can be scrolled, in REPL you can do paging. This might be a bit tricky, but I think should be doable. Thank you for your efforts. |
We already do it in DataFrames.jl. The only difference is that we do not print names of omitted columns. If you think it would be useful you can consider also opening a separate issue there. |
Hi @dylanjm ! Nice, I just need to think how to adapt this to PrettyTables, since it can print columns with different element types. |
Just wanted to chime in with my gratitude for this excellent package and interest in support for pretty printing arrays. I would really like to use it for AxisIndices.jl where there can be all sorts of labels for both rows and columns. |
Hi @Tokazama , Thank you very much for the kind words. If you need any specific feature, please, let me know! |
I've almost got something working. The one problem I can't find a good work around for is the row names. So given the following: x = reshape(1:4, (2,2))
column_names = [:c1, :c2]
row_names = [:r1, :r2] I can convert everything to the same type as the row names. pretty_table(
hcat(row_names, Symbol.(x)),
vcat(Symbol(""), column_names)
) But that's problematic if the array is very large because then the entire array needs to be converted. Besides this I think I can just do what is done in base where I repeatedly print matrix views of multidimensional arrays. |
@Tokazama I wouldn't be worried with this performance for printing tables, because if the table is really too big, it can't even fit on screen. However, you gave me an idea: we could add an option to pass a vector with row names, which will be displayed as the first columns. Does it work for you? |
The problem in my example above is that the entire array would need to be converted even if it's not all printed. Of course I could just convert the portion that I know will be printed but that would mean not taking advantage of a lot of the great work you've already done to for detecting screen size and printing the right number of characters.
That would be perfect! |
Nice! Let's see what I can do. |
Nice! Now I see what do you want. I think that having an option |
My approach is definitely inefficient because it takes a bit to print in the REPL, but I'm really impressed with how much this package has allowed me to do. You might be interested in the example I put together that essentially replaces CoefTable in the JuliaStats ecosystem. I have a screenshot here and more stuff in my documentation. |
In this commit, only the text backend is supported. This addresses a request mentioned in the issue #18.
Hi @Tokazama I have just pushed a commit in which I added the option |
By the way, I only implemented this for text backend. If the API I selected is fine, then I will do for all the other backends. |
This looks awesome! Does it make sense to have a column_names keyword? |
A column name will be the same thing as the header, won’t it? |
I guess the difference in terminology between "names" and "header" is pretty meaningful here so it probably won't be important to disambiguate. I was just thinking out loud and won't have any problems with the implementation you now have. |
Is master currently ready for a new release or is there more that needs to be done before making this feature available? |
Hi @Tokazama Sorry for the delay. The next release will be breaking. Thus, I want to use it to implement a few features I always wanted but require to break things. If everything goes right, then I think I can release |
I have a bare bones implementation of pretty printing for arrays with no dependencies but PrettyTables here. If you're interested I could make a PR to PrettyTables.jl with some minimal implementation but I'm not sure I know the coding style of PrettyTables internally well enough to do so effectively. |
Interesting, but can you please explain me what are the gains of defining a new backend for an array? It seems that the same effect can be achieved only by selecting some options to the available text back-end. Am I wrong? |
It wouldn't necessarily need all the code for printing a matrix or a vector, but this could add support for arrays with more than 2 dimensions. |
Hum, can you please show an example? |
Hum! I see. I think we can add a back-end to print multi-dimensional arrays. However, I need to think a little more about it, because it deviates from the initial purpose of this package. But your idea is very nice! Can you please open a new issue related to arrays with more than 2 dimensions? |
I will close this since PrettyTables.jl is already the text backend of DataFrames.jl. |
A common case is when a table is too wide and too long to be printed in REPL.
Currently only first rows/columns that fit the display size are printed.
It would be great if there were an option for a printout like for matrices in Base (ie. printing first and last rows/columns and dropping the ones in the middle).
Also it would be nice if, when some columns are omitted when printing, there would be an optional information what was omitted under the table (probably also truncated somehow as with 10'000 columns even listing omitted column names would swamp REPL).
The text was updated successfully, but these errors were encountered: