Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ENH: __contains__ between pd.Series and pd.Interval #53843

Open
Labels
@matteosantama

Description

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

I would like to check, element-wise, if a pd.Series is contained within a pd.Interval, ie.

pd.Series(range(10)) in pd.Interval(0, 1)

Feature Description

pd.Interval.__contains__ would have to check for a pd.Series type and then call

def __contains__(self, item: Any) -> bool | pd.Series:
 ...
 if isinstance(item, pd.Series):
 return item.apply(lambda element: element in self)

Alternative Solutions

It's easy enough to write pd.Series(range(10)).apply(lambda element: element in pd.Interval(0, 1), but the syntactic sugar proposed here would be nice.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /