Skip to content

Commit df09322

Browse files
committed
Add a test for this
1 parent 4f0ece0 commit df09322

File tree

3 files changed

+1145
-984
lines changed

3 files changed

+1145
-984
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: "Great Tables - Oceania"
3+
format: typst
4+
_quarto:
5+
tests:
6+
typst:
7+
printsMessage:
8+
level: INFO
9+
regex: 'invalid font weight initial'
10+
---
11+
12+
```{=typst}
13+
#set page(numbering: none)
14+
```
15+
16+
```{python}
17+
#| classes: plain
18+
from great_tables import GT
19+
from great_tables.data import countrypops
20+
import polars as pl
21+
import polars.selectors as cs
22+
23+
# Get vectors of 2-letter country codes for each region of Oceania
24+
oceania = {
25+
"Australasia": ["AU", "NZ"],
26+
"Melanesia": ["NC", "PG", "SB", "VU"],
27+
"Micronesia": ["FM", "GU", "KI", "MH", "MP", "NR", "PW"],
28+
"Polynesia": ["PF", "WS", "TO", "TV"],
29+
}
30+
31+
# Create a dictionary mapping country to region (e.g. AU -> Australasia)
32+
country_to_region = {
33+
country: region for region, countries in oceania.items() for country in countries
34+
}
35+
36+
wide_pops = (
37+
pl.from_pandas(countrypops)
38+
.filter(
39+
pl.col("country_code_2").is_in(list(country_to_region))
40+
& pl.col("year").is_in([2000, 2010, 2020])
41+
)
42+
.with_columns(pl.col("country_code_2").replace(country_to_region).alias("region"))
43+
.pivot(index=["country_name", "region"], columns="year", values="population")
44+
.sort("2020", descending=True)
45+
)
46+
47+
(
48+
GT(wide_pops, rowname_col="country_name", groupname_col="region")
49+
.tab_header(title="Populations of Oceania's Countries in 2000, 2010, and 2020")
50+
.tab_spanner(label="Total Population", columns=cs.all())
51+
.fmt_integer()
52+
)
53+
```

tests/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ dependencies = [
1515
"papermill>=2.6.0",
1616
"seaborn>=0.13.2",
1717
"shiny>=1.2.0",
18+
"great-tables>=0.17.0",
19+
"polars>=1.29.0",
20+
"pyarrow>=20.0.0",
1821
]

0 commit comments

Comments
 (0)