Skip to content
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

Create pl.lit from a Python set object? #17012

Closed
cmdlineluser opened this issue Jun 17, 2024 · 2 comments
Closed

Create pl.lit from a Python set object? #17012

cmdlineluser opened this issue Jun 17, 2024 · 2 comments
Labels
enhancement New feature or an improvement of an existing feature

Comments

@cmdlineluser
Copy link
Contributor

Description

This came up when using list.set_intersection where trying to pass a set raises a TypeError.

other = {'a', 'c'}
pl.select(pl.lit(['a', 'b', 'c']).list.set_intersection(other))

# TypeError: cannot create expression literal for value of type set: {'a', 'c'}

The caller must explictly convert it to a list/tuple, which feels a little awkward.

pl.select(pl.lit(['a', 'b', 'c']).list.set_intersection(list(other)))

# shape: (1, 1)
# ┌────────────┐
# │ literal    │
# │ ---        │
# │ list[str]  │
# ╞════════════╡
# │ ["a", "c"] │
# └────────────┘

Should Polars allow this and just treat it as if it were a list?

@cmdlineluser cmdlineluser added the enhancement New feature or an improvement of an existing feature label Jun 17, 2024
@alexander-beedie
Copy link
Collaborator

alexander-beedie commented Jun 17, 2024

... better to leave it up to the caller to decide if unstable sort order is acceptable for their usage

Actually, re-reading the example... the set is being provided to set_intersection, it isn't the root expression. Hmm... Let me think about that - it may not be so unreasonable that way round, though I believe there will still be element-order instability in some of the other set-function results, which I don't think we want in what are still list-namespace ops (and special-casing this method over the others would feel a bit inconsistent 🤔). Need to check what we're currently doing here in terms of stability.

@ritchie46
Copy link
Member

ritchie46 commented Jun 17, 2024

I don't think we should. It are set operations done on "lists", not on "sets". Polars doesn't have a set type and making an exception for 1 expression is not something the IR should deal with.

@cmdlineluser cmdlineluser closed this as not planned Won't fix, can't repro, duplicate, stale Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants