Skip to content

Commit 1d182cc

Browse files
committed
ENH: Support For Interval __contains__ Other Interval (pandas-dev#46613)
1 parent 2f8b74b commit 1d182cc

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pandas/_libs/interval.pyx

+5-3
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,11 @@ cdef class Interval(IntervalMixin):
411411
return hash((self.left, self.right, self.inclusive))
412412

413413
def __contains__(self, key) -> bool:
414-
if isinstance(key, Interval):
415-
return ((self.left < key.left if self.open_left and key.closed_left else self.left <= key.left) and
416-
(key.right < self.right if self.open_right and key.closed_right else key.right <= self.right))
414+
if _interval_like(key):
415+
key_closed_left = key.inclusive in ('left', 'both')
416+
key_closed_right = key.inclusive in ('right', 'both')
417+
return ((self.left < key.left if self.open_left and key_closed_left else self.left <= key.left) and
418+
(key.right < self.right if self.open_right and key_closed_right else key.right <= self.right))
417419
return ((self.left < key if self.open_left else self.left <= key) and
418420
(key < self.right if self.open_right else key <= self.right))
419421

pandas/core/indexes/range.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def __new__(
135135

136136
# validate the arguments
137137
if com.all_none(start, stop, step):
138-
raise TypeError("RangeIndex(...) must be called with integers")
138+
raise TypeError("RangeIndex(...) must be called with integers/floats")
139139

140140
start = ensure_python_int(start) if start is not None else 0
141141

0 commit comments

Comments
 (0)