{"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/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/interval.py#L1811-L1847","documentation":"Raised in IntervalArray.contains when 'other' is a pandas.Interval. The vectorized 'contains' method only checks scalar points against each interval; interval-vs-interval containment is not implemented and is explicitly rejected.","triggerScenarios":"arr.contains(pd.Interval(1, 2)); passing an Interval to contains expecting nested-containment semantics.","commonSituations":"Confusing contains with overlaps; attempting to test whether intervals nest or contain one another.","solutions":["Use arr.overlaps(other) if intersection semantics are wanted.","Implement containment manually: (arr.left <= other.left) & (other.right <= arr.right).","Iterate per-element for nested containment checks."],"exampleFix":"// before\narr.contains(pd.Interval(1, 2))\n// after\n(arr.left <= 1) & (arr.right >= 2)  # bound-wise containment check","handlingStrategy":"fallback","validationCode":"def contains_interval(arr, other):\n    # other is a pandas.Interval\n    return (arr.left <= other.left) & (other.right <= arr.right)","typeGuard":"import pandas as pd\n\ndef is_scalar_point(v):\n    return not isinstance(v, pd.Interval)","tryCatchPattern":null,"preventionTips":["Use contains only for scalar points; do not pass an Interval.","Use overlaps for interval-vs-interval intersection checks.","Implement nested-containment manually with bound comparisons."],"tags":["interval-array","contains","not-implemented"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}