Table Of Contents

Search

Enter search terms or a module, class or function name.

pandas.api.extensions.ExtensionDtype.construct_from_string

classmethod ExtensionDtype.construct_from_string(string)[source]

Attempt to construct this type from a string.

Parameters:
string : str
Returns:
self : instance of ‘cls’
Raises:
TypeError

If a class cannot be constructed from this ‘string’.

Examples

If the extension dtype can be constructed without any arguments, the following may be an adequate implementation.

>>> @classmethod
... def construct_from_string(cls, string)
...     if string == cls.name:
...         return cls()
...     else:
...         raise TypeError("Cannot construct a '{}' from "
...                         "'{}'".format(cls, string))
Scroll To Top