{"record":{"id":"3c9d04a34bdcac7b","repo":"pandas-dev/pandas","slug":"invalid-dtype-dtype","errorCode":null,"errorMessage":"invalid dtype: {dtype}","messagePattern":"invalid dtype: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/interval.py","lineNumber":609,"sourceCode":"            right.append(rhs)\n\n        return cls.from_arrays(left, right, closed, copy=False, dtype=dtype)\n\n    @classmethod\n    def _validate(cls, left, right, dtype: IntervalDtype) -> None:\n        \"\"\"\n        Verify that the IntervalArray is valid.\n\n        Checks that\n\n        * dtype is correct\n        * left and right match lengths\n        * left and right have the same missing values\n        * left is always below right\n        \"\"\"\n        if not isinstance(dtype, IntervalDtype):\n            msg = f\"invalid dtype: {dtype}\"\n            raise ValueError(msg)\n        if len(left) != len(right):\n            msg = \"left and right must have the same length\"\n            raise ValueError(msg)\n        left_mask = notna(left)\n        right_mask = notna(right)\n        if not (left_mask == right_mask).all():\n            msg = (\n                \"missing values must be missing in the same \"\n                \"location both left and right sides\"\n            )\n            raise ValueError(msg)\n        if not (left[left_mask] <= right[left_mask]).all():\n            msg = \"left side of interval must be <= right side\"\n            raise ValueError(msg)\n\n    def _shallow_copy(self, left, right) -> Self:\n        \"\"\"\n        Return a new IntervalArray with the replacement attributes","sourceCodeStart":591,"sourceCodeEnd":627,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/interval.py#L591-L627","documentation":"Raised in `_validate` when the supplied dtype is not an IntervalDtype. `_validate` is the final structural check over left/right/dtype; the dtype must be a fully-formed IntervalDtype (not a subtype string and not None after construction).","triggerScenarios":"Internal/programmatic calls that bypass `_ensure_simple_new_inputs` and pass a raw numpy dtype or string to `_validate`; constructing via `_simple_new` with a wrong dtype; pickle/reconstruction edge cases.","commonSituations":"Subclassing IntervalArray and overriding construction; custom array wrappers that forward a dtype without converting; misuse of private API.","solutions":["Use the public constructors (`IntervalArray(...)`, `from_arrays`, `from_tuples`, `from_breaks`) which produce a valid IntervalDtype.","If you must call `_validate`, build the dtype with `IntervalDtype(subtype, closed)` first.","Avoid passing strings like 'int64'; pass `IntervalDtype('int64', 'right')`."],"exampleFix":"# before (private misuse)\narr._validate(left, right, dtype='int64')\n\n# after\narr._validate(left, right, dtype=IntervalDtype('int64', 'right'))","handlingStrategy":"type-guard","validationCode":"from pandas import IntervalDtype\n\ndef ensure_interval_dtype(dtype):\n    if not isinstance(dtype, IntervalDtype):\n        raise ValueError(f'expected IntervalDtype, got {type(dtype)}')\n    return dtype","typeGuard":"from pandas import IntervalDtype\n\ndef is_interval_dtype_obj(dtype) -> bool:\n    return isinstance(dtype, IntervalDtype)","tryCatchPattern":"try:\n    arr._validate(left, right, dtype)\nexcept ValueError as e:\n    if 'invalid dtype' in str(e):\n        from pandas import IntervalDtype\n        arr._validate(left, right, IntervalDtype(dtype))\n    else:\n        raise","preventionTips":["Prefer public constructors (IntervalArray, from_arrays, from_breaks) over private _validate.","Build dtype with IntervalDtype(subtype, closed) explicitly.","Do not pass raw numpy dtypes or strings to private validate paths."],"tags":["interval","validate","interval-dtype","value-error"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}