{"record":{"id":"1eabd87d61130afc","repo":"pandas-dev/pandas","slug":"left-and-right-arrays-must-have-matching-signednes","errorCode":null,"errorMessage":"Left and right arrays must have matching signedness. Got {left_dtype} and {right_dtype}.","messagePattern":"Left and right arrays must have matching signedness\\. Got (.+?) and (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/interval.py","lineNumber":379,"sourceCode":"            lbase = getattr(left, \"_ndarray\", left)\n            lbase = getattr(lbase, \"_data\", lbase).base\n            rbase = getattr(right, \"_ndarray\", right)\n            rbase = getattr(rbase, \"_data\", rbase).base\n            if lbase is not None and lbase is rbase:\n                # If these share data, then setitem could corrupt our IA\n                right = right.copy()\n\n        dtype = IntervalDtype(left.dtype, closed=closed)\n\n        # Check for mismatched signed/unsigned integer dtypes after casting\n        left_dtype = left.dtype\n        right_dtype = right.dtype\n        if (\n            left_dtype.kind in \"iu\"\n            and right_dtype.kind in \"iu\"\n            and left_dtype.kind != right_dtype.kind\n        ):\n            raise TypeError(\n                f\"Left and right arrays must have matching signedness. \"\n                f\"Got {left_dtype} and {right_dtype}.\"\n            )\n        return left, right, dtype\n\n    @classmethod\n    def _from_sequence(\n        cls,\n        scalars,\n        *,\n        dtype: Dtype | None = None,\n        copy: bool = False,\n    ) -> Self:\n        return cls(scalars, dtype=dtype, copy=copy)\n\n    @classmethod\n    def _from_factorized(cls, values: np.ndarray, original: IntervalArray) -> Self:\n        return cls._from_sequence(values, dtype=original.dtype)","sourceCodeStart":361,"sourceCodeEnd":397,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/interval.py#L361-L397","documentation":"Raised as a TypeError after dtype coercion when both bounds are integer-kind but one is signed and the other unsigned (e.g., int64 vs uint64). Mixing signedness would silently corrupt comparisons, so pandas refuses. Fires at pandas/core/arrays/interval.py:379.","triggerScenarios":"`pd.IntervalIndex.from_arrays(np.array([1,2], dtype='int64'), np.array([3,4], dtype='uint64'))`, or merging columns whose numpy dtypes came from different sources (e.g., Arrow vs numpy).","commonSituations":"Combining data from pyarrow (often uint) with numpy (often int); indexing/groupby code paths that upcast lengths to uint.","solutions":["Cast both bounds to the same signed int dtype: `left.astype('int64')`, `right.astype('int64')`.","If values fit in unsigned range, cast both to uint64: `left.astype('uint64')`.","Promote to float64 if you cannot guarantee int range: `left.astype('float64')`."],"exampleFix":"// before\npd.IntervalIndex.from_arrays(left_i64, right_u64)\n// after\npd.IntervalIndex.from_arrays(left_i64, right_u64.astype('int64'))","handlingStrategy":"validation","validationCode":"import numpy as np\n\ndef unify_signedness(left, right, target='int64'):\n    left = np.asarray(left).astype(target)\n    right = np.asarray(right).astype(target)\n    return left, right","typeGuard":"import numpy as np\n\ndef same_signedness(left, right) -> bool:\n    ld = np.asarray(left).dtype\n    rd = np.asarray(right).dtype\n    return not (ld.kind in 'iu' and rd.kind in 'iu' and ld.kind != rd.kind)","tryCatchPattern":"try:\n    ia = pd.IntervalArray(left, right)\nexcept TypeError as e:\n    if \"matching signedness\" in str(e):\n        ia = pd.IntervalArray(left.astype('int64'), right.astype('int64'))\n    else:\n        raise","preventionTips":["Cast both bound arrays to the same int dtype before constructing.","Be wary of pyarrow-derived uint64 lengths mixed with numpy int64.","Promote to float64 if range cannot be guaranteed."],"tags":["interval","dtype","integer","signedness","constructor"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}