posit-dev / great-tables

Make awesome display tables using Python.
https://posit-dev.github.io/great-tables/
MIT License
1.42k stars 48 forks source link

Fix nanoplots listcols #330

Closed machow closed 1 month ago

machow commented 1 month ago

This PR ensures Great Tables can render a polars DataFrame that has a pl.List column. Previously, it would error, and the error was early enough that formatters couldn't work with this data.

(Note that most formatters are not designed to work with list columns. We may need to support this down the road, or add helpful messaging when erroring in these cases).

(Note also that this might fail for complex list schemas, eg. nested lists like pl.List(pl.List(int)) rather than pl.List(int). But this case also fails in the current code).

Here's a hokey example displaying a table with list columns:

from great_tables import GT
import polars as pl

GT(pl.DataFrame({"x": [[1, 2], [3]], "y": [[.9], [1.1]]}))
image

And with a tasty nanoplot

GT(pl.DataFrame({"x": [[1, 2], [3]], "y": [[.9], [1.1]]})).fmt_nanoplot("x")
image