[ANN] PrettyTables v3.0.0

Hi!

Finally, I’ve completed the first release of PrettyTables.jl version 3! For anyone using this package, we can assume that everything in the API has changed (sorry about that :D). However, these breaking changes have very good reasons.

We now adhere to the table structure defined in R’s package GT. This results in a more coherent table design and a plethora of additional features, such as merging column labels (headers), adding summary rows, adding footnotes, and many more!

Since I am not a native English speaker, the keyword naming was previously inconsistent. I’ve taken great care to ensure coherence now. While the keyword names may be lengthy, they are highly meaningful.

We’ve introduced a true markdown backend, enhancing the package’s functionality.

The package has significantly improved its speed.

The internal structure has been streamlined, introducing a centralized printing state iterator. This simplifies the process of adding new backends, as each backend no longer needs to iterate through the table sections individually.

If anyone want a quick example, try this:

julia> matrix = [(i, j) for i in 1:3, j in 1:3];

julia> pretty_table(
    matrix;
    column_labels            = [["Col. 1", MultiColumn(2, "Merged Column")], ["$i" for i in 1:3]],
    footnotes                = [(:column_label, 1, 2) => "Footnote in column label", (:data, 2, 2) => "Footnote in data"],
    row_group_labels         = [2 => "Row Group"],
    row_labels               = ["Row $i" for i in 1:5],
    show_row_number_column   = true,
    source_notes             = "Source Notes",
    stubhead_label           = "Rows",
    subtitle                 = "Table Subtitle",
    summary_rows             = [(data, i) -> 10i, (data, i) -> 20i],
    title                    = "Table Title",
)

Please, expect some bugs and issues. If you find one, I appreciate if you can open a ticket in github!

In the coming days, I will submit a pull request to DataFrames.jl (@bkamins) to use the new version. In this case, it will have the same output, with minor improvements in edge cases. However, after the initial merge, we can begin incorporating the new features from PrettyTables.jl to enhance the output of DataFrames.jl.

75 Likes

That’s great news. Congratulations and thanks for all your work @Ronis_BR!

2 Likes

I’ve already started using it. It’s really great!

1 Like

Thank you @Ronis_BR !

How to reproduce header_crayon in the new release? I’ve tried playing with TextTableStyle without success. Appreciate your help:

Hi @juliohm !

You can use first_line_column_label in TextTableStyle structure for the first line (which we called header) and column_label for the other lines (which we called subheaders).

@Ronis_BR I tried it, but in our use case we have multiple colors in the first row. The first_line_column_label only accepts a single color.

1 Like

Ah! So you want different colors for different column labels? I dropped this feature because I thought nobody was using it :smiley:

I will add it again.

4 Likes

I don’t know if this would be an alternative for your use case @juliohm, but I noticed that PrettyTables.jl v3 is compatible with StyledStrings.jl (which is pretty nice!). So different colors in the column labels would be possible using StyledStrings.jl

6 Likes

Thanks @JoshuaLampert ! I really forgot we could do this :smiley: But yes, we have full support for StyledStrings.jl.

Anyway, to keep consistency with the previous version, I added the feature back as requested by @juliohm . It will be available in v3.0.1 (I am treating the lack of this feature as a bug). Now, we can do this:

If you use both, StyledStrings.jl and the style keyword, the former has precedence.

3 Likes

Is this meant to be subhead_label?

1 Like

Actually no! I followed the naming convention in R’s package GT (https://gt.rstudio.com):

EDIT: Except for the “Spanner Column Label” which I called “Merged Column Label” because we can merge any adjacent column labels and instead of only the ones in the top of the hierarchy.

5 Likes

Thank you @Ronis_BR @JoshuaLampert , everything works now in the :text backend :100:

Is there an equivalent in HtmlTableStyle? I noticed that it expects a Vector{Pair} instead.

:smiley: I forgot that I have to change this in all backends! I will do that.

1 Like

I wonder if these style options are generic enough to become independent of backend. Perhaps a general style = TableStyle(...) could be introduced?

Yes! This is something we can add! The idea is to have a general style that converts to a backend specific call. We just need to design a good API.

1 Like

TIL. Had never heard of a “stub head” before

2 Likes

@Ronis_BR I think @JoshuaLampert’s suggestion with styled strings is more general. It works for all backends. My PR is almost there, I am just having trouble to compare HTML output with special escape characters (colors):

Off-topic: do you know how to properly escape these color characters in sprint tests? The last test in the PR above is failing with a parsing error:

<th style = "text-align: center; font-weight: bold;">\e[35m\e[1ma\e[39m\e[22m</th>

Yes, indeed! However, it is good to provide the other option for the case where the user cannot change the column labels for some reason.

Can you please provide more detail? I am not sure if it is correct to mix ANSI escape sequences in HTML output.

@juliohm

I think I understood. To use StyledString in HTML we need to use renderer = :show. Furthermore I need to correct a bug :slight_smile: I will do this to allow you to use this approach.

1 Like