plesty.lib.data.types

Type resolution and casting utilities for Plesty data types.

Functions

resolve_dtype(...)

Resolve schema dtype strings into Python types.

resolve_array_item_dtype(→ Any)

Resolve the NumPy item dtype from an array dtype token like array_float32.

normalize_shape(→ tuple[Any, Ellipsis] | None)

Normalize a shape specification into a tuple, or return None.

istype(→ bool)

Check if a value is of a specified data type, including basic and iterable types.

cast_basic_type(→ Any)

Cast a value to the given basic type, raising ValueError on failure.

Module Contents

plesty.lib.data.types.resolve_dtype(dtype: Any) type[Any] | plesty.lib.data.ctype_manager.CtypeParam | None

Resolve schema dtype strings into Python types.

Supports scalar aliases and array types in the form array_<numpy_dtype>, e.g. array_float, array_int32, array_float64.

Parameters:

dtype (Any)

Return type:

type[Any] | plesty.lib.data.ctype_manager.CtypeParam | None

plesty.lib.data.types.resolve_array_item_dtype(dtype: Any) Any

Resolve the NumPy item dtype from an array dtype token like array_float32.

Parameters:

dtype (Any)

Return type:

Any

plesty.lib.data.types.normalize_shape(shape: Any) tuple[Any, Ellipsis] | None

Normalize a shape specification into a tuple, or return None.

Parameters:

shape (Any)

Return type:

tuple[Any, Ellipsis] | None

plesty.lib.data.types.istype(value: Any, dtype: Any) bool

Check if a value is of a specified data type, including basic and iterable types.

Parameters:
  • value (Any)

  • dtype (Any)

Return type:

bool

plesty.lib.data.types.cast_basic_type(value: Any, dtype: Any) Any

Cast a value to the given basic type, raising ValueError on failure.

Parameters:
  • value (Any)

  • dtype (Any)

Return type:

Any