{"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":"validation","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/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/interval.py#L361-L397","documentation":"Raised at the end of `_ensure_simple_new_inputs` after all dtype coercion: if both endpoints are integer-kind (`kind in 'iu'`) but one is signed and the other unsigned (e.g. int64 vs uint64), the signedness mismatch is rejected because IntervalArray cannot pick a single canonical integer dtype and silent overflow would occur.","triggerScenarios":"`IntervalArray.from_arrays(np.array([0,1], dtype='int64'), np.array([1,2], dtype='uint64'))`; mixing numpy default int with explicitly-typed unsigned arrays from ctypes/cython layers; downcasting from int64 to uint32 on one side via astype.","commonSituations":"Interfacing with libraries that emit unsigned arrays (hash codes, bitmask endpoints); explicit `dtype='uint32'` on one bound only; cross-platform int width differences.","solutions":["Cast both endpoints to the same signed integer dtype: `right.astype('int64')` (or both to unsigned if values fit).","Cast both to float64 if values may exceed the signed range.","Normalise at ingestion: ensure both bounds use `np.int64` before constructing."],"exampleFix":"# before\nIntervalArray.from_arrays(np.array([0,1], dtype='int64'), np.array([1,2], dtype='uint64'))\n\n# after\nIntervalArray.from_arrays(np.array([0,1], dtype='int64'), np.array([1,2], dtype='int64'))","handlingStrategy":"validation","validationCode":"import numpy as np\n\ndef unify_signedness(left, right):\n    lk, rk = left.dtype.kind, right.dtype.kind\n    if lk in 'iu' and rk in 'iu' and lk != rk:\n        right = right.astype(left.dtype)\n    return left, right","typeGuard":"def matching_signedness(left, right) -> bool:\n    lk, rk = left.dtype.kind, right.dtype.kind\n    return not (lk in 'iu' and rk in 'iu' and lk != rk)","tryCatchPattern":"try:\n    arr = IntervalArray.from_arrays(left, right)\nexcept TypeError as e:\n    if 'matching signedness' in str(e):\n        right = right.astype(left.dtype)\n        arr = IntervalArray.from_arrays(left, right)\n    else:\n        raise","preventionTips":["Cast both integer endpoints to a single signed dtype (e.g. np.int64) at ingestion.","Watch for unsigned arrays coming from ctypes/cython/hash code layers.","Use float64 when integer bounds may exceed the signed range."],"tags":["interval","signedness","integer-dtype","type-error"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}