Skip to content

ENH: Add is_empty attribute to Interval structures #27219

Closed
@jschendel

Description

@jschendel

An is_empty attribute would be useful, as it is often necessary to special case empty intervals when dealing with Interval methods such as overlaps, contains, etc. (xref #26893)

For a scalar Interval this should return a boolean:

In [2]: pd.Interval(0, 0, closed='neither').is_empty
Out[2]: True

In [3]: pd.Interval(0, 1, closed='neither').is_empty
Out[3]: False

For an IntervalIndex or IntervalArray this should return a boolean ndarray positionally indicating if a given Interval is empty:

In [4]: pd.IntervalIndex.from_tuples([(0, 0), (0, 1)]).is_empty
Out[4]: array([ True, False])

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions