From adda75bd2d3c2bbb5a3eaa4daa4058f4aa4f228e Mon Sep 17 00:00:00 2001
From: Jules <54960783+juleswg23@users.noreply.github.com>
Date: Mon, 11 Aug 2025 09:58:33 -0400
Subject: [PATCH 01/11] first pass, adding gt-extras example
---
docs/examples/index.qmd | 192 ++++++++++++++++++++++++++++++++++++++++
pyproject.toml | 3 +-
2 files changed, 194 insertions(+), 1 deletion(-)
diff --git a/docs/examples/index.qmd b/docs/examples/index.qmd
index fe1a50fd2..281e5ef17 100644
--- a/docs/examples/index.qmd
+++ b/docs/examples/index.qmd
@@ -419,3 +419,195 @@ coffee_table
:::::
::::::
+## Ecosystem
+
+:::::: {.column-page}
+::::: {.grid}
+
+:::{.g-col-lg-6 .g-col-12 .shrink-example}
+
+??? post ⬀
+
+
+```{python}
+# | echo: false
+import polars as pl
+from great_tables import GT, html
+import gt_extras as gte
+
+pre_tax_col = "gini_market__age_total"
+post_tax_col = "gini_disposable__age_total"
+
+# Read the data
+df = pl.read_csv(
+ "https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-08-05/income_inequality_raw.csv",
+ schema={
+ "Entity": pl.String,
+ "Code": pl.String,
+ "Year": pl.Int64,
+ post_tax_col: pl.Float64,
+ pre_tax_col: pl.Float64,
+ "population_historical": pl.Int64,
+ "owid_region": pl.String,
+ },
+ null_values=["NA", ""],
+)
+
+# Propogate the region field to all rows of that country
+df = (
+ df.sort("Entity")
+ .group_by("Entity", maintain_order=True)
+ .agg(
+ [
+ pl.col("Code"),
+ pl.col("Year"),
+ pl.col(post_tax_col),
+ pl.col(pre_tax_col),
+ pl.col("population_historical"),
+ # Most important action happens here
+ pl.col("owid_region").fill_null(strategy="backward"),
+ ]
+ )
+ .explode(
+ [
+ "Code",
+ "Year",
+ post_tax_col,
+ pre_tax_col,
+ "population_historical",
+ "owid_region",
+ ]
+ )
+)
+
+# Drop rows where there is a null in either pre-tax or post-tax cols
+df = df.drop_nulls(
+ subset=(
+ pl.col(post_tax_col),
+ pl.col(pre_tax_col),
+ )
+)
+
+# Compute the percent reduction in gini coefficient.
+df = df.with_columns(
+ ((pl.col(pre_tax_col) - pl.col(post_tax_col)) / pl.col(pre_tax_col) * 100)
+ .round(2)
+ .alias("gini_pct_change")
+)
+
+# Calculate 5-year benchmark (mean) of percent change for each country
+df = df.with_columns(
+ pl.col("gini_pct_change")
+ .rolling_mean(window_size=5)
+ .over(pl.col("Entity"))
+ .alias("gini_pct_benchmark_5yr")
+)
+
+# Select rows with large population in the year 2020, sorted by coefficient post-tax
+df = (
+ # Choose a smaller pop to include more countries
+ df.filter(pl.col("population_historical").gt(40000000))
+ .filter(pl.col("Year").eq(2020))
+ .sort(by=pl.col(post_tax_col))
+)
+
+
+# Scale population
+df = df.with_columns((pl.col("population_historical").log10()).alias("pop_log"))
+pop_min = df["pop_log"].min() / 1
+pop_max = df["pop_log"].max()
+
+# Set up gt-extras icons, scaling population to 1-10 range
+df = df.with_columns(
+ ((pl.col("pop_log") - pop_min) / (pop_max - pop_min) * 10 + 1)
+ .round(0)
+ .cast(pl.Int64)
+ .alias("pop_icons")
+)
+
+# Format original population value with commas
+df = df.with_columns(
+ pl.col("population_historical").map_elements(
+ lambda x: f"{int(x):,}" if x is not None else None, return_dtype=pl.String
+ )
+)
+
+# Apply gte.fa_icon_repeat to each entry in the pop_icons column
+df_with_icons = df.with_columns(
+ pl.col("pop_icons").map_elements(
+ lambda x: gte.fa_icon_repeat(name="person", repeats=int(x)),
+ return_dtype=pl.String,
+ )
+)
+
+# Generate the table, before gt-extras add-ons
+gt = (
+ GT(df_with_icons, rowname_col="Entity", groupname_col="owid_region")
+ .tab_header(
+ "Income Inequality Before and After Taxes in 2020",
+ "As measured by the Gini coefficient, where 0 is best and 1 is worst",
+ )
+ .cols_move("pop_icons", after=pre_tax_col)
+ .cols_align("left")
+ .cols_hide(["Year", "pop_log", "population_historical"])
+ .fmt_flag("Code")
+ .cols_label(
+ {
+ "Code": "",
+ "gini_pct_change": "Improvement Post Taxes",
+ "pop_icons": "Population",
+ }
+ )
+ .tab_source_note(
+ html(
+ """
+
+
Source: Data from
#TidyTuesday (2025-08-05).
+
+ Dumbbell plot:
+ Blue: post-tax Gini coefficient
+ Gold: pre-tax Gini coefficient
+
+
+
Bullet plot: Percent reduction in Gini after taxes for each country, compared to its 5-year average benchmark.
+
+ """
+ )
+ )
+)
+
+# Apply the gt-extras functions via pipe
+(
+ gt.pipe(
+ gte.gt_plt_dumbbell,
+ col1=pre_tax_col,
+ col2=post_tax_col,
+ col1_color="#e0b165",
+ col2_color="#106ea0",
+ dot_border_color="transparent",
+ num_decimals=2,
+ width=240,
+ label="Pre-tax to Post-tax Coefficient",
+ )
+ .pipe(
+ gte.gt_plt_bullet,
+ "gini_pct_change",
+ "gini_pct_benchmark_5yr",
+ fill="#963d4c",
+ target_color="#3D3D3D",
+ bar_height=15,
+ width=200,
+ )
+ .pipe(
+ gte.gt_merge_stack,
+ col1="pop_icons",
+ col2="population_historical",
+ )
+ .pipe(gte.gt_theme_guardian)
+)
+```
+
+:::
diff --git a/pyproject.toml b/pyproject.toml
index bb43b2c1f..a4f570785 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -81,7 +81,8 @@ dev-no-pandas = [
"pytest-cov",
"shiny",
"svg.py",
- "syrupy"
+ "syrupy",
+ "gt-extras"
]
[project.urls]
From bb8a48d66a4ab9388ebd484e002feacfe1a4cdce Mon Sep 17 00:00:00 2001
From: Jules <54960783+juleswg23@users.noreply.github.com>
Date: Mon, 11 Aug 2025 10:59:36 -0400
Subject: [PATCH 02/11] Clean up page as a whole
---
docs/examples/index.qmd | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/docs/examples/index.qmd b/docs/examples/index.qmd
index 281e5ef17..48b8cc438 100644
--- a/docs/examples/index.qmd
+++ b/docs/examples/index.qmd
@@ -7,6 +7,7 @@ format:
html:
code-fold: true
code-summary: "Show the Code"
+toc: false
---
:::::: {.column-page}
@@ -429,7 +430,7 @@ coffee_table
??? post ⬀
+ >See the code (gt-extras site) ⬀
```{python}
@@ -611,3 +612,6 @@ gt = (
```
:::
+
+:::::
+::::::
From 66b28724c5f52fc5e06c23ea2c99c629532863ca Mon Sep 17 00:00:00 2001
From: Jules <54960783+juleswg23@users.noreply.github.com>
Date: Mon, 11 Aug 2025 11:05:09 -0400
Subject: [PATCH 03/11] lock gt-extras at current version, 0.0.7 (or newer)
---
pyproject.toml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pyproject.toml b/pyproject.toml
index a4f570785..4aac7100f 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -73,6 +73,7 @@ dev-no-pandas = [
"jupyter",
"quartodoc>=0.11.0; python_version >= '3.9'",
"griffe==0.38.1",
+ "gt-extras>=0.0.7",
"polars",
"pre-commit==2.15.0",
"pyarrow",
@@ -81,8 +82,7 @@ dev-no-pandas = [
"pytest-cov",
"shiny",
"svg.py",
- "syrupy",
- "gt-extras"
+ "syrupy"
]
[project.urls]
From 8df73615d5291bc90ce955b403bb938850ec8334 Mon Sep 17 00:00:00 2001
From: Jules <54960783+juleswg23@users.noreply.github.com>
Date: Mon, 11 Aug 2025 13:52:08 -0400
Subject: [PATCH 04/11] no release version
---
pyproject.toml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pyproject.toml b/pyproject.toml
index 4aac7100f..dffe80cc2 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -73,7 +73,7 @@ dev-no-pandas = [
"jupyter",
"quartodoc>=0.11.0; python_version >= '3.9'",
"griffe==0.38.1",
- "gt-extras>=0.0.7",
+ "gt-extras",
"polars",
"pre-commit==2.15.0",
"pyarrow",
From 2ab1d80df0e6e33376e01d31f23e95fe1bef1dc3 Mon Sep 17 00:00:00 2001
From: Jules <54960783+juleswg23@users.noreply.github.com>
Date: Mon, 11 Aug 2025 13:54:03 -0400
Subject: [PATCH 05/11] add fallback version
---
pyproject.toml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/pyproject.toml b/pyproject.toml
index dffe80cc2..9afccc525 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -3,6 +3,7 @@ requires = ["setuptools>=45", "wheel", "setuptools_scm>=6.2"]
build-backend = "setuptools.build_meta"
[tool.setuptools_scm]
+fallback_version = "0.18.0"
[tool.setuptools.packages.find]
include = ["great_tables"]
@@ -73,7 +74,7 @@ dev-no-pandas = [
"jupyter",
"quartodoc>=0.11.0; python_version >= '3.9'",
"griffe==0.38.1",
- "gt-extras",
+ "gt-extras>=0.0.6",
"polars",
"pre-commit==2.15.0",
"pyarrow",
From 85d5d354a6bc9433c33f9150e640e87591886301 Mon Sep 17 00:00:00 2001
From: Jules <54960783+juleswg23@users.noreply.github.com>
Date: Mon, 11 Aug 2025 15:08:42 -0400
Subject: [PATCH 06/11] revert last two commits, instead resolve #760
---
pyproject.toml | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/pyproject.toml b/pyproject.toml
index 9afccc525..4aac7100f 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -3,7 +3,6 @@ requires = ["setuptools>=45", "wheel", "setuptools_scm>=6.2"]
build-backend = "setuptools.build_meta"
[tool.setuptools_scm]
-fallback_version = "0.18.0"
[tool.setuptools.packages.find]
include = ["great_tables"]
@@ -74,7 +73,7 @@ dev-no-pandas = [
"jupyter",
"quartodoc>=0.11.0; python_version >= '3.9'",
"griffe==0.38.1",
- "gt-extras>=0.0.6",
+ "gt-extras>=0.0.7",
"polars",
"pre-commit==2.15.0",
"pyarrow",
From 2cc918094dbd762c553482b4eab11f84943a8864 Mon Sep 17 00:00:00 2001
From: Jules <54960783+juleswg23@users.noreply.github.com>
Date: Mon, 11 Aug 2025 16:41:36 -0400
Subject: [PATCH 07/11] install gt-extras "manually" in CI docs workflow
---
.github/workflows/ci-docs.yaml | 1 +
pyproject.toml | 1 -
2 files changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/ci-docs.yaml b/.github/workflows/ci-docs.yaml
index 4b13d9ef9..7cd8c037f 100644
--- a/.github/workflows/ci-docs.yaml
+++ b/.github/workflows/ci-docs.yaml
@@ -20,6 +20,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install ".[all]"
+ python -m pip install gt-extras>=0.0.7
- uses: quarto-dev/quarto-actions/setup@v2
with:
tinytex: true
diff --git a/pyproject.toml b/pyproject.toml
index 4aac7100f..bb43b2c1f 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -73,7 +73,6 @@ dev-no-pandas = [
"jupyter",
"quartodoc>=0.11.0; python_version >= '3.9'",
"griffe==0.38.1",
- "gt-extras>=0.0.7",
"polars",
"pre-commit==2.15.0",
"pyarrow",
From 21e5fb4e798cb951d72c4d0469d12b4c6c149391 Mon Sep 17 00:00:00 2001
From: Jules <54960783+juleswg23@users.noreply.github.com>
Date: Thu, 28 Aug 2025 11:54:43 -0400
Subject: [PATCH 08/11] fetch depth: 0
---
.github/workflows/ci-docs.yaml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/.github/workflows/ci-docs.yaml b/.github/workflows/ci-docs.yaml
index 7cd8c037f..190cafaf4 100644
--- a/.github/workflows/ci-docs.yaml
+++ b/.github/workflows/ci-docs.yaml
@@ -14,6 +14,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.10"
From 8ea64b668cc96e99fd27b339f08234858bf5c671 Mon Sep 17 00:00:00 2001
From: Jules <54960783+juleswg23@users.noreply.github.com>
Date: Thu, 28 Aug 2025 11:58:40 -0400
Subject: [PATCH 09/11] change with: fetch-depth: 0 in all places
---
.github/workflows/ci-tests.yaml | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/.github/workflows/ci-tests.yaml b/.github/workflows/ci-tests.yaml
index 1d643f9b3..0b742194e 100644
--- a/.github/workflows/ci-tests.yaml
+++ b/.github/workflows/ci-tests.yaml
@@ -20,6 +20,8 @@ jobs:
steps:
- uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
@@ -44,6 +46,8 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
@@ -59,6 +63,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
@@ -83,6 +89,8 @@ jobs:
#
- uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
@@ -108,6 +116,8 @@ jobs:
if: github.event_name == 'release'
steps:
- uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
- uses: actions/setup-python@v2
with:
python-version: "3.10"
From ca3944e25bcd4eea09385bd648c36522ecd192b1 Mon Sep 17 00:00:00 2001
From: Jules <54960783+juleswg23@users.noreply.github.com>
Date: Thu, 28 Aug 2025 11:58:53 -0400
Subject: [PATCH 10/11] add gt-extras back as a dependency
---
pyproject.toml | 1 +
1 file changed, 1 insertion(+)
diff --git a/pyproject.toml b/pyproject.toml
index bb43b2c1f..4aac7100f 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -73,6 +73,7 @@ dev-no-pandas = [
"jupyter",
"quartodoc>=0.11.0; python_version >= '3.9'",
"griffe==0.38.1",
+ "gt-extras>=0.0.7",
"polars",
"pre-commit==2.15.0",
"pyarrow",
From 6e0f42952e6915eb9abdc00b8958a6980d2c5652 Mon Sep 17 00:00:00 2001
From: Jules <54960783+juleswg23@users.noreply.github.com>
Date: Thu, 28 Aug 2025 12:19:13 -0400
Subject: [PATCH 11/11] delete pip install gt-extras
---
.github/workflows/ci-docs.yaml | 1 -
1 file changed, 1 deletion(-)
diff --git a/.github/workflows/ci-docs.yaml b/.github/workflows/ci-docs.yaml
index 190cafaf4..461f3e2a3 100644
--- a/.github/workflows/ci-docs.yaml
+++ b/.github/workflows/ci-docs.yaml
@@ -22,7 +22,6 @@ jobs:
- name: Install dependencies
run: |
python -m pip install ".[all]"
- python -m pip install gt-extras>=0.0.7
- uses: quarto-dev/quarto-actions/setup@v2
with:
tinytex: true