Skip to content

Commit

Permalink
Merge pull request #371 from posit-dev/feat-init-methods
Browse files Browse the repository at this point in the history
Feat init methods
  • Loading branch information
machow authored Jun 6, 2024
2 parents 5a67bee + 0426c83 commit 82f66ad
Show file tree
Hide file tree
Showing 17 changed files with 587 additions and 138 deletions.
3 changes: 3 additions & 0 deletions docs/_quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ quartodoc:
contents:
- GT.tab_header
- GT.tab_spanner
- GT.tab_stub
- GT.tab_stubhead
- GT.tab_source_note
- GT.tab_style
Expand Down Expand Up @@ -155,6 +156,8 @@ quartodoc:
[`tab_stubhead()`](`great_tables.GT.tab_stubhead`), and
[`tab_source_note()`](`great_tables.GT.tab_source_note`) methods.
contents:
- GT.with_id
- GT.with_locale
- md
- html
- from_column
Expand Down
6 changes: 4 additions & 2 deletions docs/examples/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ islands_mini = (
)
(
GT(islands_mini, rowname_col="name")
GT(islands_mini)
.tab_header(
title="Large Landmasses of the World",
subtitle="The top ten largest are presented"
)
.tab_stub(rowname_col="name")
.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.")
Expand Down Expand Up @@ -108,9 +109,10 @@ wide_pops = (
)
(
GT(wide_pops, rowname_col="country_name", groupname_col="region")
GT(wide_pops)
.tab_header(title="Populations of Oceania's Countries in 2000, 2010, and 2020")
.tab_spanner(label="Total Population", columns=cs.all())
.tab_stub(rowname_col="country_name", groupname_col="region")
.fmt_integer()
)
```
Expand Down
21 changes: 18 additions & 3 deletions docs/get-started/basic-stub.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ from great_tables.data import islands
islands_mini = islands.head(10)
GT(islands_mini, rowname_col="name")
GT(islands_mini).tab_stub(rowname_col="name")
```

Notice that the landmass names are now placed to the left? That's the **Stub**. Notably, there is a prominent border to the right of it but there's no label above the **Stub**. We can change this and apply what's known as a *stubhead label* through use of the [`tab_stubhead()`](`great_tables.GT.tab_stubhead`) method:

```{python}
(
GT(islands_mini, rowname_col="name")
GT(islands_mini)
.tab_stub(rowname_col="name")
.tab_stubhead(label="landmass")
)
```
Expand All @@ -37,5 +38,19 @@ Let's incorporate row groups into the display table. This divides rows into grou
```{python}
island_groups = islands.head(10).assign(group = ["subregion"] * 2 + ["country"] * 2 + ["continent"] * 6)
GT(island_groups, rowname_col="name", groupname_col="group").tab_stubhead(label="landmass")
(
GT(island_groups)
.tab_stub(rowname_col="name", groupname_col="group")
.tab_stubhead(label="landmass")
)
```

## GT convenience arguments

Rather than using the `GT.tab_stub()` method, the `GT(rowname_col=..., groupname_col=...)` arguments
provide a quick way to specify row names and groups.


```{python}
GT(island_groups, rowname_col="name", groupname_col="group")
```
2 changes: 1 addition & 1 deletion great_tables/_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ._gt_data import Body, Boxhead, RowGroups, Stub


def body_reassemble(body: Body, row_groups: RowGroups, stub_df: Stub, boxhead: Boxhead) -> Body:
def body_reassemble(body: Body, stub_df: Stub, boxhead: Boxhead) -> Body:
# Note that this used to order the body based on groupings, but now that occurs in the
# renderer itself.
return body.__class__(copy_data(body.body))
Loading

0 comments on commit 82f66ad

Please sign in to comment.