{"record":{"id":"e0cd4eab24140cab","repo":"pandas-dev/pandas","slug":"invalid-dtype-specified-dtype","errorCode":null,"errorMessage":"invalid dtype specified {dtype}","messagePattern":"invalid dtype specified (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/numeric.py","lineNumber":124,"sourceCode":"    def _get_dtype_mapping(cls) -> Mapping[np.dtype, NumericDtype]:\n        raise AbstractMethodError(cls)\n\n    @classmethod\n    def _standardize_dtype(cls, dtype: NumericDtype | str | np.dtype) -> NumericDtype:\n        \"\"\"\n        Convert a string representation or a numpy dtype to NumericDtype.\n        \"\"\"\n        if isinstance(dtype, str) and (dtype.startswith((\"Int\", \"UInt\", \"Float\"))):\n            # Avoid DeprecationWarning from NumPy about np.dtype(\"Int64\")\n            # https://github.com/numpy/numpy/pull/7476\n            dtype = dtype.lower()\n\n        if not isinstance(dtype, NumericDtype):\n            mapping = cls._get_dtype_mapping()\n            try:\n                dtype = mapping[np.dtype(dtype)]\n            except KeyError as err:\n                raise ValueError(f\"invalid dtype specified {dtype}\") from err\n        return dtype\n\n    @classmethod\n    def _safe_cast(cls, values: np.ndarray, dtype: np.dtype, copy: bool) -> np.ndarray:\n        \"\"\"\n        Safely cast the values to the given dtype.\n\n        \"safe\" in this context means the casting is lossless.\n        \"\"\"\n        raise AbstractMethodError(cls)\n\n\ndef _coerce_to_data_and_mask(values, dtype, copy: bool, dtype_cls: type[NumericDtype]):\n    checker = dtype_cls._checker\n    default_dtype = dtype_cls._default_np_dtype\n\n    mask = None\n    inferred_type = None","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/numeric.py#L106-L142","documentation":"Raised by NumericDtype._standardize_dtype when the supplied dtype does not map to any known masked numeric numpy dtype in the internal mapping (KeyError on the mapping lookup). Only the canonical masked numeric dtypes (Int8..Int64, UInt8..UInt64, Float32/Float64) are accepted.","triggerScenarios":"Passing an unrecognized dtype string or numpy dtype such as pd.array(values, dtype='Int128'), dtype='S', dtype=complex, or any non-numeric masked dtype name to a masked numeric construction path.","commonSituations":"Typos in dtype strings ('itn64'); attempting to use a dtype pandas does not support as nullable numeric (complex, bytes); passing lowercase aliases that don't match the masked convention.","solutions":["Use a supported masked numeric dtype: 'Int8','Int16','Int32','Int64','UInt8'..'UInt64','Float32','Float64'.","Check spelling/case: masked dtypes are capitalized (Int64 not int64 for the nullable variant).","For plain numpy dtypes use the non-nullable path (dtype='int64')."],"exampleFix":"// before\npd.array([1, 2], dtype=\"Int128\")  # raises: invalid dtype specified Int128\n\n// after\npd.array([1, 2], dtype=\"Int64\")","handlingStrategy":"validation","validationCode":"SUPPORTED = {\"Int8\",\"Int16\",\"Int32\",\"Int64\",\"UInt8\",\"UInt16\",\"UInt32\",\"UInt64\",\"Float32\",\"Float64\"}\n\ndef validate_dtype(dtype):\n    name = getattr(dtype, \"name\", str(dtype))\n    if name not in SUPPORTED:\n        raise ValueError(f\"unsupported masked numeric dtype: {dtype}\")\n    return dtype","typeGuard":"def is_supported_masked_numeric_dtype(dtype) -> bool:\n    SUPPORTED = {\"Int8\",\"Int16\",\"Int32\",\"Int64\",\"UInt8\",\"UInt16\",\"UInt32\",\"UInt64\",\"Float32\",\"Float64\"}\n    return getattr(dtype, \"name\", str(dtype)) in SUPPORTED","tryCatchPattern":"try:\n    arr = pd.array(vals, dtype=dtype)\nexcept ValueError as e:\n    if \"invalid dtype specified\" in str(e):\n        arr = pd.array(vals, dtype=\"Int64\")  # safe fallback\n    else:\n        raise","preventionTips":["Use the canonical capitalized masked dtype names.","Validate dtype strings against the supported set in config layers.","Distinguish nullable (Int64) from numpy (int64) dtypes explicitly."],"tags":["numeric-array","dtype","validation"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}