Skip to content

Should Series.__contains__ look at indexes or values? #5571

Closed
@danielballan

Description

@danielballan

When writing this SO answer, I came upon this behavior, which I did not expect.

In [1]: 1 in Series([1])
Out[1]: False

In [2]: 1 in Series([1, 2])
Out[2]: True

Apparently, __contains__ looks at the index.

In [3]: 1 in Series([1], index=[1])
Out[3]: True

I can see how that makes sense. But I think it's fair to say that it is potentially confusing. Do we rely on this behavior of __contains__ for data alignment? Might it be reasonable to change it? I'm not sure that's a good idea, but I want to raise the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions