{"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/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/numeric.py#L106-L142","documentation":"Raised by NumericDtype._standardize_dtype when the input dtype string or np.dtype does not map to any registered NumericDtype in the dtype mapping. The mapping only covers supported numpy dtypes (e.g. int8/16/32/64, uint8/16/32/64, float32/64); anything else triggers a KeyError that is converted into this ValueError.","triggerScenarios":"Passing an unsupported dtype to a nullable numeric array constructor or astype, e.g. pd.array(values, dtype='Int128'), or a numpy dtype like np.dtype('complex128') / datetime64 to NumericDtype._standardize_dtype.","commonSituations":"Typos in dtype strings; requesting dtypes pandas nullable arrays do not support (Int128, complex, float16 on some paths); passing a numpy dtype object that does not round-trip to a registered NumericDtype.","solutions":["Use a supported nullable numeric dtype: 'Int8','Int16','Int32','Int64','UInt8'..'UInt64','Float32','Float64'.","For complex/datetime/other data, choose the matching pandas dtype instead of a NumericDtype.","Print np.dtype(dtype) to confirm the canonical numpy dtype before passing it in."],"exampleFix":"// before\npd.array([1, 2, 3], dtype='Int128')   # raises\n// after\npd.array([1, 2, 3], dtype='Int64')","handlingStrategy":"validation","validationCode":"import numpy as np\nfrom pandas.core.arrays.numeric import NumericDtype\nmapping = NumericDtype._get_dtype_mapping()\nif np.dtype(dtype) not in mapping:\n    raise ValueError(f'Unsupported NumericDtype: {dtype}')","typeGuard":"def is_supported_numeric_dtype(dtype) -> bool:\n    import numpy as np\n    from pandas.core.arrays.numeric import NumericDtype\n    return np.dtype(dtype) in NumericDtype._get_dtype_mapping()","tryCatchPattern":"try:\n    arr = pd.array(values, dtype=dtype)\nexcept ValueError as e:\n    if 'invalid dtype specified' in str(e):\n        arr = pd.array(values, dtype='Int64')\n    else:\n        raise","preventionTips":["Restrict dtype strings to the supported nullable numeric set.","Validate via the dtype mapping before constructing arrays.","Prefer canonical names (Int64, Float64) over ad-hoc strings."],"tags":["pandas","numeric-array","dtype","constructor"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}