posit-dev / great-tables

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

Support using polars.element() like a lambda for various calculations #251

Open machow opened 3 months ago

machow commented 3 months ago

Functions like fmt_nanoplot() have arguments that support calculation expressions on data. For example, reference_line= can take arguments like "min", which then calculates the min.

It would be great if we could just take a polars expression there. One issue is that afaik there isn't a way to pass an "anonymous" expression in polars. Meaning, an expression that says "do this set of calculations to some unnamed Series, that will be specified later".

However, a very similar mechanism exists for lists already in polars. You can use polars.element() to essentially do the above, for each list in a column with a schema like List[*].

I wonder if there's a way to tap into this mechanism more generally? E.g.


# pretty good, but not as extensible ---
GT(...).fmt_nanoplot(reference_line="min")

#  plz we need it ---
GT(...).fmt_nanoplot(reference_line=pl.element().min())

(I could be missing another feature in polars that does this already)