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

fix: check input type for arr/list.contains #13959

Merged
merged 2 commits into from
Jan 25, 2024

Conversation

reswqa
Copy link
Collaborator

@reswqa reswqa commented Jan 24, 2024

Almost all operations in list/arr namespace ensures the input type when unpack series. But contains is an exception due to the reuse of is_in ops. As a result, you can even call arr.contains on list series.

IMO, we should raise for things like ListSeries.arr.xxx or ArraySeries.list.xxx. After all, they are not essentially the same type. In particular, you can't even convert a list to an array with unequal width.

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Jan 24, 2024
@reswqa reswqa marked this pull request as ready for review January 24, 2024 16:26
@mcrumiller
Copy link
Contributor

mcrumiller commented Jan 24, 2024

Should list.contains(array_item) and arr.contains(list_item) be allowed? I kind of think so. Array is a special case of List whereby a property of the lists (their length) is constrainted, but the items themselves can still be considered identical.

I think, though, that we should not allow .arr.contains on series with dtype List. What do others think?

Edit to clarify:

s_list = pl.Series([[1, 2]], dtype=pl.List(pl.Int32))
s_arr = pl.Series([[1, 2]], dtype=pl.Array(pl.Int32, 2))

s_list.list.contains(s_arr)  # should be allowed, and should return [True], as items are identical
s_arr.arr.contains(s_list)   # same

s_list.arr.contains(...)     # should not be allowed, list are too broad to call array methods
s_arr.list.contains(...)     # should be allowed, arrays are specialized lists

stinodego
stinodego previously approved these changes Jan 25, 2024
Copy link
Member

@stinodego stinodego left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @reswqa!

@stinodego stinodego dismissed their stale review January 25, 2024 09:04

Actually, could you add a test for these?

@stinodego
Copy link
Member

Actually let met add a test myself real quick, I'm on this PR now anyway!

@stinodego stinodego merged commit 0c70388 into pola-rs:main Jan 25, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants