great-tables
great-tables copied to clipboard
feat: add `tab_spanner_delim()` method
Fix issue: #582.
Hello team:
This PR sets up a scaffold for tab_spanner_delim().
Basic Logic:
- Use
str.splitorstr.rsplitto split column names, corresponding todelimi=andlimit=parameters. - Iterate through selected columns, splitting each name and recording its
levelandroot_col(original column). - Process the recorded info:
- If
level != 0, calltab_spanner(). - If
level == 0, callcols_label().
- If
Example:
import polars as pl
from great_tables import GT
data = {
"province.NL_ZH.pop": [1, 2, 3],
"province.NL_ZH.gdp": [4, 5, 6],
"province.NL_NH.pop": [7, 8, 9],
"province.NL_NH.gdp": [10, 11, 12],
}
gt = GT(pl.DataFrame(data))
gt.tab_spanner_delim()
gt.tab_spanner_delim(limit=1)
gt.tab_spanner_delim(split="first", limit=1)
Remaining Tasks:
- [ ] The
reverse=logic is not implemented—need the team's help to clarify the expected behavior. - [ ] Docs are ported from
{gt}but need refinement. - [ ] Tests are missing since the logic isn't fully settled yet.