question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ENH: Interval.__contains__(self, other: Interval)

See original GitHub issue

Is your feature request related to a problem?

Not a problem. Just a feature I would have liked to have! 😃

I would like to be able to know if an Interval is contained into another Interval.

e.g. [2, 3) is contained in [2, 4) but not in (2, 4]

Describe the solution you’d like

Something like this

def interval_contains(a: pd.Interval, b: pd.Interval) -> bool:
    res = a.left <= b.left and a.right >= b.right
    if a.open_left and b.closed_left:
        res &= a.left < b.left
    if a.open_right and b.closed_right:
        res &= a.right > b.right
    return res

API breaking implications

Currently, if you do something like this

a = pd.Interval(2, 3, closed="left")
b = pd.Interval(2, 4, closed="left")
print(a in b)

it raises the following exception

TypeError: __contains__ not defined for two intervals

Adding support for another type of object in __contains__ would not break the API, but just extend it.

Describe alternatives you’ve considered

Could not find any.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
venaturumcommented, Apr 8, 2022
0reactions
kapiliyercommented, Jul 27, 2022

take

Read more comments on GitHub >

github_iconTop Results From Across the Web

Example: an interval type — Numba 0.50.1 documentation
As the Interval class is not known to Numba, we must create a new Numba type to represent instances of it. Numba does...
Read more >
MAT 240: Module 5 Notes Confidence Intervals
An interval estimate is a range of values that is likely to contain the parameter being estimated. Combined with a probability statement, an...
Read more >
A Survey of Health Care Practitioners' Knowledge of the QT ...
Anonymous, self-administered questionnaire that included 20 questions on the QT interval. MEASUREMENTS AND MAIN RESULTS. Of approximately 826 ...
Read more >
Why Use Imprecise Probability?
Interval is as simple as a pair of numbers, i.e. the lower and upper bounds. The reason to choose interval is two-fold. First,...
Read more >
Nested Containment List (NCList): a new algorithm for ...
We can easily solve this problem by realizing that it is caused solely by the intervals that are contained within other intervals, i.e....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found