Skip to content

QST: Method for comparing Series[Timestamp] to Interval #40243

Open
@andymcarter

Description

@andymcarter

I have recently discovered the IntervalArray type, which has been really useful to replace two or more date comparisons with a single call. But I got a bit stuck in a simpler situation. Is there a natural pandas API for comparing a series of Timestamps to a single pd.Interval, that respects the closed nature of the Interval? At the minute I am using:

df['end_date'].between(MY_INTERVAL.left, MY_INTERVAL.right)

But I feel like I'm looking for something like this:

df['end_date'].dt.isin(MY_INTERVAL)

I couldn't find anything in the documentation that would give me a vectorised solution, am I just looking for something that isn't there?

  • I have searched the [pandas] tag on StackOverflow for similar questions.

  • I have asked my usage related question on StackOverflow.

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