Polars selectors can be used in a wide range of GT methods within the columns= argument. While the fmt_*() and cols_*() methods have good support for this, using a Polars selector fails with cols_hide(). Here is some code that fails with this approach:
from great_tables import GT, exibble
import polars as pl
import polars.selectors as cs
exibble_pl = pl.from_pandas(exibble)
(
GT(exibble_pl)
.cols_hide(columns=cs.starts_with("date"))
)
Stack trace on my machine:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
File ...great-tables/playground.qmd:8
3 import polars.selectors as cs
5 exibble_pl = pl.from_pandas(exibble)
7 (
----> 8 GT(exibble_pl)
9 .cols_hide(columns=cs.starts_with("date"))
10 )
File ...great-tables/great_tables/_spanners.py:470, in cols_hide(data, columns)
468 if not len(sel_cols):
469 raise Exception("No columns selected.")
--> 470 elif not all([col in vars for col in columns]):
471 raise ValueError("All `columns` must exist and be visible in the input `data` table.")
473 # New boxhead with hidden columns
TypeError: '_selector_proxy_' object is not iterable
Polars selectors can be used in a wide range of GT methods within the
columns=
argument. While thefmt_*()
andcols_*()
methods have good support for this, using a Polars selector fails withcols_hide()
. Here is some code that fails with this approach:Stack trace on my machine: