You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of Polars.
Issue description
First, thanks for developing this amazing library! Coming from R, I feel like polars is as good as data.table (and this really means something to me!).
TL; DR: I would like to use filter like this: df.filter(pl.col("myvar") in liste_values), and I can't find how to do it. I read the documentation carefully but did not find anything on this specific point.
Details:
I frequently select rows in dataframes by a condition where the value of a column must be in a list of values. In pandas, I use this syntax : df.query('cars in ["beetle", "SUV"]').
For some reason, I couldn't figure out how to the same thing in polars. I think I might not understand completely how Expressions work in polars, given that I get an error ValueError: Since Expr are lazy, the truthiness of an Expr is ambiguous. Hint: use '&' or '|' to chain Expr together, not and/or.
Question:
Is there a simple syntax that would make it possible to use this filtering method? Of course, I can propose a PR on the documentation to add some details on this use case if there is a solution.
Thanks a lot @gfmartins! Although I thought I had read it carefully, the solution was indeed in the documentation... Sorry for opening a pointless issue!
@oliviermeslin: FYI, I'm adding a little extra help to the error that gets raised here, to point anyone else doing the same thing in the right direction 👍
# ValueError: Since Expr are lazy, the truthiness of an Expr is ambiguous. # Hint: use '&' or '|' to logically combine Expr, not 'and'/'or', and# use 'x.is_in([y,z])' instead of 'x in [y,z]' to check membership.
Polars version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of Polars.
Issue description
First, thanks for developing this amazing library! Coming from
R
, I feel likepolars
is as good asdata.table
(and this really means something to me!).TL; DR: I would like to use filter like this:
df.filter(pl.col("myvar") in liste_values)
, and I can't find how to do it. I read the documentation carefully but did not find anything on this specific point.Details:
pandas
, I use this syntax :df.query('cars in ["beetle", "SUV"]')
.polars
. I think I might not understand completely how Expressions work inpolars
, given that I get an errorValueError: Since Expr are lazy, the truthiness of an Expr is ambiguous. Hint: use '&' or '|' to chain Expr together, not and/or.
Question:
Is there a simple syntax that would make it possible to use this filtering method? Of course, I can propose a PR on the documentation to add some details on this use case if there is a solution.
Reproducible example
Expected behavior
Installed versions
The text was updated successfully, but these errors were encountered: