pandas-dev/pandas · error · TypeError

Cannot construct a '{cls.__name__}' from '{string}'

Error message

Cannot construct a '{cls.__name__}' from '{string}'

What it means

construct_from_string accepts only the literal names 'string', 'str' (when the experimental string_dtype config is enabled), 'string[python]', and 'string[pyarrow]'. Any other string falls through to the else branch and raises TypeError indicating the name cannot be resolved to a StringDtype.

Source

Thrown at pandas/core/arrays/string_.py:309

        Raise
        -----
        TypeError
            If the string is not a valid option.
        """
        if not isinstance(string, str):
            raise TypeError(
                f"'construct_from_string' expects a string, got {type(string)}"
            )
        if string == "string":
            return cls()
        elif string == "str" and using_string_dtype():
            return cls(na_value=np.nan)
        elif string == "string[python]":
            return cls(storage="python")
        elif string == "string[pyarrow]":
            return cls(storage="pyarrow")
        else:
            raise TypeError(f"Cannot construct a '{cls.__name__}' from '{string}'")

    def construct_array_type(self) -> type_t[BaseStringArray]:
        """
        Return the array type associated with this dtype.

        Returns
        -------
        type
        """
        from pandas.core.arrays.string_arrow import (
            ArrowStringArray,
        )

        if self.storage == "python" and self._na_value is libmissing.NA:
            return StringArray
        elif self.storage == "pyarrow" and self._na_value is libmissing.NA:
            return ArrowStringArray
        elif self.storage == "python":

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Use one of the valid names: 'string', 'string[python]', 'string[pyarrow]' (or 'str' under the experimental config).
  2. Double-check spelling, especially the 'pyarrow' suffix.
  3. If you need a different dtype, use its own construct_from_string or pandas_dtype().

Example fix

// before
StringDtype.construct_from_string('string[arrow]')

// after
StringDtype.construct_from_string('string[pyarrow]')
Defensive patterns

Strategy: validation

Validate before calling

VALID = {'string', 'string[python]', 'string[pyarrow]'}
if name not in VALID:
    raise ValueError(f'Invalid string dtype name: {name}')
dtype = pd.StringDtype.construct_from_string(name)

Type guard

VALID = {'string', 'string[python]', 'string[pyarrow]'}

def is_valid_string_dtype_name(s: str) -> bool:
    return isinstance(s, str) and s in VALID

Try / catch

try:
    dtype = pd.StringDtype.construct_from_string(name)
except TypeError:
    dtype = pd.StringDtype()

Prevention

When it happens

Trigger: Calling construct_from_string('string[foo]'), construct_from_string('object'), construct_from_string('int64'), construct_from_string('StringDtype'), or any unrecognized dtype string.

Common situations: Typos in dtype strings; passing a dtype name belonging to a different dtype; using a storage suffix that does not exist (e.g., 'string[arrow]' instead of 'string[pyarrow]').

Related errors


AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07). Data as JSON: /api/errors/f38fa69fe2a80240. Report an issue: GitHub.