{"record":{"id":"27aecda2111198d2","repo":"pandas-dev/pandas","slug":"contains-not-implemented-for-two-intervals","errorCode":null,"errorMessage":"contains not implemented for two intervals","messagePattern":"contains not implemented for two intervals","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/interval.py","lineNumber":1829,"sourceCode":"        See Also\n        --------\n        Interval.contains : Check whether Interval object contains value.\n        IntervalArray.overlaps : Check if an Interval overlaps the values in the\n            IntervalArray.\n\n        Examples\n        --------\n        >>> intervals = pd.arrays.IntervalArray.from_tuples([(0, 1), (1, 3), (2, 4)])\n        >>> intervals\n        <IntervalArray>\n        [(0, 1], (1, 3], (2, 4]]\n        Length: 3, dtype: interval[int64, right]\n\n        >>> intervals.contains(0.5)\n        array([ True, False, False])\n        \"\"\"\n        if isinstance(other, Interval):\n            raise NotImplementedError(\"contains not implemented for two intervals\")\n\n        return (self._left < other if self.open_left else self._left <= other) & (\n            other < self._right if self.open_right else other <= self._right\n        )\n\n    def isin(self, values: ArrayLike) -> npt.NDArray[np.bool_]:\n        if isinstance(values, IntervalArray):\n            if self.closed != values.closed:\n                # not comparable -> no overlap\n                return np.zeros(self.shape, dtype=bool)\n\n            if self.dtype == values.dtype:\n                left = self._combined\n                right = values._combined\n                return np.isin(left, right).ravel()\n\n            elif needs_i8_conversion(self.left.dtype) ^ needs_i8_conversion(\n                values.left.dtype","sourceCodeStart":1811,"sourceCodeEnd":1847,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/interval.py#L1811-L1847","documentation":"Raised by IntervalArray.contains when 'other' is itself a pd.Interval. The vectorized contains check is defined for scalar points only; interval-vs-interval containment is not implemented and the code explicitly refuses rather than returning a misleading result.","triggerScenarios":"Calling arr.contains(pd.Interval(0, 1)) instead of arr.contains(0.5).","commonSituations":"Users reaching for contains expecting it to behave like overlaps; library code that pipes interval filters through contains.","solutions":["Use arr.overlaps(other_interval) for overlap semantics, or compute containment manually via (arr.left <= other.left) & (arr.right >= other.right).","If checking whether a single point lies in any interval, pass the scalar directly: arr.contains(0.5).","Loop point-by-point if you truly need interval containment per element."],"exampleFix":"# before\narr.contains(pd.Interval(0, 1))\n\n# after\n(arr.left <= 0) & (arr.right >= 1)","handlingStrategy":"type-guard","validationCode":"def contains_arg(value):\n    if isinstance(value, pd.Interval):\n        raise TypeError('use overlaps or manual containment, not contains')\n    return value","typeGuard":"def is_not_interval(value) -> bool:\n    return not isinstance(value, pd.Interval)","tryCatchPattern":null,"preventionTips":["Use .contains only for scalar points.","Use .overlaps for interval-vs-interval overlap; compute containment manually if needed.","Type-check the argument at the call site."],"tags":["interval-array","not-implemented","contains"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}