abracudabra._validate#

Attributes#

LIBRARY_TO_CONCRETE_TYPES

Mapping from library names to functions that return a mapping of concrete types.

Classes#

Library

Library names.

Functions#

_get_numpy_type(→ dict[str, type])

_get_cupy_type(→ dict[str, type])

_get_torch_type(→ dict[str, type])

_get_pandas_type(→ dict[str, type])

_get_cudf_type(→ dict[str, type])

_get_concrete_types(→ type | tuple[type, Ellipsis])

validate_obj_type(…)

Validate an object ensuring it matches the type from a specified library.

Module Contents#

abracudabra._validate._get_numpy_type() dict[str, type][source]#
abracudabra._validate._get_cupy_type() dict[str, type][source]#
abracudabra._validate._get_torch_type() dict[str, type][source]#
abracudabra._validate._get_pandas_type() dict[str, type][source]#
abracudabra._validate._get_cudf_type() dict[str, type][source]#
class abracudabra._validate.Library(*args, **kwds)[source]#

Bases: enum.Enum

Library names.

numpy = 'numpy'[source]#
cupy = 'cupy'[source]#
torch = 'torch'[source]#
pandas = 'pandas'[source]#
cudf = 'cudf'[source]#
abracudabra._validate.LIBRARY_TO_CONCRETE_TYPES: dict[Library, collections.abc.Callable[[], collections.abc.Mapping[str, type]]][source]#

Mapping from library names to functions that return a mapping of concrete types.

abracudabra._validate._get_concrete_types(library: Library, types: str | collections.abc.Iterable[str] | None = None) type | tuple[type, Ellipsis][source]#
abracudabra._validate.validate_obj_type(obj: object, /, library: Literal[Library], types: str | collections.abc.Iterable[str] | None = ...) TypeGuard[numpy.ndarray][source]#
abracudabra._validate.validate_obj_type(obj: object, /, library: Literal[Library], types: str | collections.abc.Iterable[str] | None = ...) TypeGuard[Any]
abracudabra._validate.validate_obj_type(obj: object, /, library: Literal[Library], types: str | collections.abc.Iterable[str] | None = ...) TypeGuard[torch.Tensor]
abracudabra._validate.validate_obj_type(obj: object, /, library: Literal[Library], types: str | collections.abc.Iterable[str] | None = ...) TypeGuard[pandas.Index | pandas.Series[Any] | pandas.DataFrame]
abracudabra._validate.validate_obj_type(obj: object, /, library: Literal[Library], types: str | collections.abc.Iterable[str] | None = ...) TypeGuard[cudf.Index | cudf.Series | cudf.DataFrame]
abracudabra._validate.validate_obj_type(obj: object, /, library: Library, types: str | collections.abc.Iterable[str] | None = ...) bool

Validate an object ensuring it matches the type from a specified library.

Parameters:
  • obj – The object to validate.

  • library – Library name from Enum ‘Library’.

  • types – The type(s) to validate against. For example, 'array', 'index', 'series', 'dataframe', 'tensor'.

Returns:

The input object, if validation succeeds.

Raises:
  • ValueError – If an unsupported library is provided.

  • TypeError – If the object type doesn’t match the expected type.