H5datatype#

class h5pandas.HDF5Dtype(*args, **kwargs)[source]#

DataType associated with HDF5ExtensionArray.

classmethod construct_array_type() Type[ExtensionArray][source]#

Return the array type associated with this dtype.

Returns#

type

classmethod construct_from_string(string: str) ExtensionDtypeT[source]#

Construct this type from a string.

This is useful mainly for data types that accept parameters. For example, a period dtype accepts a frequency parameter that can be set as period[H] (where H means hourly frequency).

By default, in the abstract class, just the name of the type is expected. But subclasses can overwrite this method to accept parameters.

Parameters#

stringstr

The name of the type, for example category.

Returns#

ExtensionDtype

Instance of the dtype.

Raises#

TypeError

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

Examples#

For extension dtypes with arguments the following may be an adequate implementation.

>>> @classmethod
... def construct_from_string(cls, string):
...     pattern = re.compile(r"^my_type\[(?P<arg_name>.+)\]$")
...     match = pattern.match(string)
...     if match:
...         return cls(**match.groupdict())
...     else:
...         raise TypeError(
...             f"Cannot construct a '{cls.__name__}' from '{string}'"
...         )
empty(shape: tuple[int, ...]) Type[ExtensionArray][source]#

Construct an ExtensionArray of this dtype with the given shape.

Analogous to numpy.empty.

Parameters#

shape : int or tuple[int]

Returns#

ExtensionArray

classmethod is_dtype(dtype: object) bool[source]#

Check if we match ‘dtype’.

Parameters#

dtypeobject

The object to check.

Returns#

bool

Notes#

The default implementation is True if

  1. cls.construct_from_string(dtype) is an instance of cls.

  2. dtype is an object and is an instance of cls

  3. dtype has a dtype attribute, and any of the above conditions is true for dtype.dtype.

property itemsize: str#

The element size of this data-type object.

See Also#

numpy.dtype.kind

property kind: str#

A character code (one of ‘biufcmMOSUV’), default ‘O’.

This should match the NumPy dtype used when the array is converted to an ndarray, which is probably ‘O’ for object if the extension type cannot be represented as a built-in NumPy type.

See Also#

numpy.dtype.kind

property na_value: object#

Default NA value to use for this type.

This is used in e.g. ExtensionArray.take. This should be the user-facing “boxed” version of the NA value, not the physical NA value for storage. e.g. for JSONArray, this is an empty dictionary.

property name: str#

A string identifying the data type.

Will be used for display in, e.g. Series.dtype

property names: list[str] | None#

Ordered list of field names, or None if there are no fields.

This is for compatibility with NumPy arrays, and may be removed in the future.

property type: Type[Any]#

The scalar type for the array, e.g. int.

It’s expected ExtensionArray[item] returns an instance of ExtensionDtype.type for scalar item, assuming that value is valid (not NA). NA values do not need to be instances of type.