posit-dev / great-tables

Make awesome display tables using Python.
https://posit-dev.github.io/great-tables/
MIT License
1.43k stars 48 forks source link

Row styles are not applied to rowname_col when rowname_col is specified #284

Open rasmi opened 2 months ago

rasmi commented 2 months ago

I am trying to create a line that runs across the top of the last row of my table (to separate the "Total" row from the rest of the table). This works great using .tab_style, but when I also specify rowname_col, the style is removed from the rowname_col column. I would expect that that the defined tab_style still works regardless of whether rowname_col is specified.

Reproducible example

(adapted from the docs)

With rowname_col

Screenshot 2024-04-12 15 11 25

Without rowname_col

Screenshot 2024-04-12 15 11 44

import polars as pl
from great_tables import GT, md, html, style, loc
from great_tables.data import islands

islands_mini = (
    pl.from_pandas(islands).sort("size", descending=True)
    .head(10)
)

(
    GT(islands_mini,
       rowname_col="name" # Comment out this line to show intended style.
    )
    .tab_header(
        title="Large Landmasses of the World",
        subtitle="The top ten largest are presented"
    )
    .tab_source_note(source_note="Source: The World Almanac and Book of Facts, 1975, page 406.")
    .tab_source_note(
        source_note=md("Reference: McNeil, D. R. (1977) *Interactive Data Analysis*. Wiley.")
    )
    .tab_stubhead(label="landmass")
    .fmt_integer(columns="size")
    .tab_style(
      style=style.borders(sides=["top"], style="double", weight="4px"),
      locations=loc.body(rows=[-1])
    )
)

Development environment

machow commented 2 months ago

Thanks for raising -- this hits a tricky piece with how we've broken apart table structure. Basically, without rowname_col there is no row stub, just a table body. This means the line crosses the whole table.

With rowname_col specified, there is a row stub. So we need to also tell it to underline that row in the row stub. This should be supported once we complete #170, since it will allow you to use loc.stub() in addition to loc.body() for underlining.

rasmi commented 2 months ago

Makes sense, thank you!