Closed jrycw closed 1 month ago
I'm curious if we could implement this feature by changing the line from
https://github.com/posit-dev/great-tables/blob/7eae1f269a7d1f787de7a2c9198d775933794fd5/great_tables/_tbl_data.py#L322
to if not isinstance(expr, (list, cls_selector, pl.Expr)):
.
Hey, thanks for raising this -- I think this was intentional, but supporting expressions seems fair to consider.
I think the rationale was:
pl.col("a")
is a selection step that's part of a broader API expressing computation (e.g. pl.col("a") + pl.col("b")
)cs.by_name("a")
seems equivalent to pl.col()
, but its type is selector specificHowever, since...
pl.col("a")
can still be fed to cs.expand_selector()
cs.by_name("a") + pl.col("b")
)I could see how people might want to use pl.col()
? It seems like where selection should occur was pretty actively discussed a while back (https://github.com/pola-rs/polars/issues/13757; see https://github.com/pola-rs/polars/issues/13757#issuecomment-1903966834 for good language on selection vs expression, etc..).
It might be a good idea to wait a bit and see where the API is a year from now? IMO it's helpful that requiring a selector nudges people away from expressions in column selection. But I could see why pl.col()
is convenient (as evidenced by that issue).
As a slightly related point, I noticed that cs.expand_selector()
actually returns the resulting column names. We use it to select columns, so this behavior could cause issues for us. I opened an issue in case it's a bug.
@machow, I'll close the issue for now and revisit it when the API from Polars
is stable. Perhaps after Polars
v1.0 is released might be a good timing.
It appears that while we currently support column selection using
Polars
selectors,Polars
expressions are not yet supported. Is this intentional? Should we consider adding support forPolars
expressions as well?