-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a way to test for list equality #10138
Comments
You need to wrap [1] in a list otherwise it's interpreted as an int #7879. Also you need to add it before you filter on it. Not sure why it's not working within the filter. I think I saw an issue about this before. data.with_columns(pl.lit([[1]]).alias('y')).filter(pl.col('x') == pl.col('y')) |
Something seems to go wrong when we inline the predicate. Will take a look later |
Having to assign a new column (and delete it afterwards) also makes for a more cumbersome user experience. |
This was asked again today on stackoverflow: https://stackoverflow.com/questions/77002768/how-to-filter-a-polars-dataframe-with-list-type-columns The current workaround for adding a new column seems to be (casting to numerics if necessary e.g. df.filter(pl.col("x").hash() != pl.lit([[1]]).hash())
# shape: (2, 1)
# ┌───────────┐
# │ x │
# │ --- │
# │ list[i64] │
# ╞═══════════╡
# │ [1, 2] │
# │ [2, 3] │
# └───────────┘ Was also asked a couple of weeks ago: https://stackoverflow.com/questions/76875762/filter-on-listint64-dtype-in-polars |
Problem description
I'm currently working with a dataset that contains list columns, and I was surprised not to find an easy way to test for list equality:
Maybe I missed the right incantation from the
Expr.list
namespace?In the meantime I went with the following utility function:
The text was updated successfully, but these errors were encountered: