ladybug_pandas.extension_types.dtype module

class ladybug_pandas.extension_types.dtype.LadybugDType(data_type=None, unit=None)[source]

Bases: ExtensionDtype

classmethod construct_array_type()[source]

Return the array type associated with this dtype.

Return type:

type

classmethod construct_from_header(header: Header)[source]

[summary]

Parameters:

[description] (header {Header} --) –

Returns:

[type] – [description]

classmethod construct_from_string(string)[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:

string (str) – The name of the type, for example category.

Returns:

Instance of the dtype.

Return type:

ExtensionDtype

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}'"
...         )
classmethod is_dtype(dtype: object) → bool

Check if we match ‘dtype’.

Parameters:

dtype (object) – The object to check.

Return type:

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.

to_header()[source]

Cast the ExtensionDtyp to a ladybug header object

Returns:

Header – A ladybug header object

property data_type_name
property kind

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

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

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.