{"record":{"id":"f38fa69fe2a80240","repo":"pandas-dev/pandas","slug":"cannot-construct-a-cls-name-from-string","errorCode":null,"errorMessage":"Cannot construct a '{cls.__name__}' from '{string}'","messagePattern":"Cannot construct a '(.+?)' from '(.+?)'","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/string_.py","lineNumber":309,"sourceCode":"        Raise\n        -----\n        TypeError\n            If the string is not a valid option.\n        \"\"\"\n        if not isinstance(string, str):\n            raise TypeError(\n                f\"'construct_from_string' expects a string, got {type(string)}\"\n            )\n        if string == \"string\":\n            return cls()\n        elif string == \"str\" and using_string_dtype():\n            return cls(na_value=np.nan)\n        elif string == \"string[python]\":\n            return cls(storage=\"python\")\n        elif string == \"string[pyarrow]\":\n            return cls(storage=\"pyarrow\")\n        else:\n            raise TypeError(f\"Cannot construct a '{cls.__name__}' from '{string}'\")\n\n    def construct_array_type(self) -> type_t[BaseStringArray]:\n        \"\"\"\n        Return the array type associated with this dtype.\n\n        Returns\n        -------\n        type\n        \"\"\"\n        from pandas.core.arrays.string_arrow import (\n            ArrowStringArray,\n        )\n\n        if self.storage == \"python\" and self._na_value is libmissing.NA:\n            return StringArray\n        elif self.storage == \"pyarrow\" and self._na_value is libmissing.NA:\n            return ArrowStringArray\n        elif self.storage == \"python\":","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/string_.py#L291-L327","documentation":"Thrown by StringDtype.construct_from_string in pandas/core/arrays/string_.py:309 when the input string does not match any of the recognized spellings ('string', 'str' under future infer_string, 'string[python]', 'string[pyarrow]'). The fall-through else branch raises TypeError listing the offending string so the dtype registry can treat it as 'not a StringDtype name'.","triggerScenarios":"Passing 'string[numpy]', 'object', 'category', 'str' (when infer_string is not enabled), 'string[arrow]' (typo), or any unrecognized dtype name to construct_from_string. Indirectly triggered by pd.api.types.pandas_dtype('string[foo]').","commonSituations":"Typo in a dtype string in a config file or constructor call. Using 'str' as a dtype name without enabling the future infer_string behavior. Third-party code passing a stale spelling removed in a pandas upgrade.","solutions":["Use a supported spelling: 'string', 'string[python]', or 'string[pyarrow]'.","If you meant plain Python strings, use dtype='object' or enable pd.options.future.infer_string = True then use 'str'.","Double-check the spelling against the docstring table in StringDtype.construct_from_string."],"exampleFix":"// before\npd.StringDtype.construct_from_string('string[arrow]')  # typo, raises\n\n// after\npd.StringDtype.construct_from_string('string[pyarrow]')","handlingStrategy":"validation","validationCode":"VALID = {'string', 'string[python]', 'string[pyarrow]'}\ndef safe_construct(name):\n    if name not in VALID:\n        raise ValueError(f'{name!r} not in {VALID}')\n    return pd.StringDtype.construct_from_string(name)","typeGuard":"null","tryCatchPattern":"try:\n    return pd.StringDtype.construct_from_string(name)\nexcept TypeError:\n    return None  # fall back to object dtype","preventionTips":["Cross-check dtype strings against the docstring table of construct_from_string.","For plain Python strings use 'string[python]' or enable infer_string and use 'str'.","Wrap user-supplied dtype names in a whitelist at the config boundary."],"tags":["string-dtype","dtype-registry","typo"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}