Skip to content

ENH: Add is_empty attribute to Interval structures #27219

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

Closed
jschendel opened this issue Jul 3, 2019 · 0 comments · Fixed by #27221
Closed

ENH: Add is_empty attribute to Interval structures #27219

jschendel opened this issue Jul 3, 2019 · 0 comments · Fixed by #27221
Labels
Enhancement Interval Interval data type
Milestone

Comments

@jschendel
Copy link
Member

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])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Interval Interval data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant