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

feat: support polars non-strict expand_selector #368

Closed machow closed 1 month ago

machow commented 1 month ago

This PR adds support for polars expressions to be used in column selection in addition to polars selectors. It requires polars v0.20.30, but falls back to the old behavior (or requiring a selector object) otherwise.

Note that this is the result of a chain of things:

Which resulted in polars super quickly adding broader support for accepting Expressions and selectors that only result in column selection (and not e.g. transformation, or aliasing; PR https://github.com/pola-rs/polars/pull/16479).

I tried to give reasonably helpful error messages for people who are not on v0.20.3 that use Expr, but also suspect people will upgrade polaras patch versions fairly quickly.

Example

from great_tables import exibble, GT

GT(pl.from_pandas(exibble)).tab_spanner("A", [pl.col("fctr"), pl.all().exclude("date")])

Note both that a list is supported along with the use of expressions (e.g. pl.col("fctr"))

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 86.11%. Comparing base (e3649d2) to head (f879854). Report is 12 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #368 +/- ## ========================================== + Coverage 85.90% 86.11% +0.21% ========================================== Files 41 41 Lines 4328 4337 +9 ========================================== + Hits 3718 3735 +17 + Misses 610 602 -8 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

machow commented 1 month ago

@jrycw if you have a min, do you mind taking a look? Hopefully this rounds out our polars column selection work!

jrycw commented 1 month ago

@machow it's amazing how quickly Polars is supporting our use case. I need to grab a coffee and take a detailed look at this, as it might impact how users utilize it.