-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: .isin() method should use __contains__ rather than __iter__ for user-defined classes to determine presence. #59041
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
Comments
I'd be okay with leaking a bit of the implementation details in the docstring - that |
I believe the real-life example I have might not be the best programming practice. In my scenario, I have a dictionary that maps item names to item instances, and the Still, I think that the current |
Can you elaborate what the contradiction is? |
I believe my comment might be misleading :) It's not the contradiction in general for Python (of course |
I'm good with a note that we use |
take |
Hello,
I think there is yes: bloom filters.
The problem is that you cannot iterate on such data structures, it doesn't make sense. The only thing you can do is test the membership of an element. |
@Ezibenroc - are you able to use |
Good point, it is slightly less readable, but it should work well, thank you! |
My main opposition to supporting this in isin is that it would require making isin use a non-vectorized approach, which makes the semantics more confusing. |
Feature Type
Adding new functionality to pandas
Changing existing functionality in pandas
Removing existing functionality in pandas
Problem Description
Right now, if you would define a user class:
and would then initialize a pandas dataframe like this:
and would then call the
.isin()
method like this:you would actually get this output:
which is if the values from
self.another_collections
specified in__iter__
are checked, rather thanself.collection
from__contains__
. I do realize that this might stem from compatibility with other libraries, but this seems counter-intuitive.Feature Description
A solution I suggest is either to change the behavior (which might result into ruining some peoples code, I believe), or adding a flag (which would lead to more complexity, I guess).
Alternative Solutions
See above.
Additional Context
No response
The text was updated successfully, but these errors were encountered: