scitex_core.types

Type definitions and type checking utilities for scitex-core.

This module provides: - ArrayLike: Type hint for array-like objects (lists, tuples, numpy arrays) - ColorLike: Type hint for color specifications (strings, RGB/RGBA tuples) - Type checking utilities for validating list element types

scitex_core.types.is_array_like(obj)[source]

Check if object is array-like.

Checks for basic array-like types including lists, tuples, numpy arrays, and PyTorch tensors (if available).

Parameters:

obj (Any) – Object to check

Returns:

True if object is array-like, False otherwise

Return type:

bool

Examples

>>> from scitex_core.types import is_array_like
>>> import numpy as np
>>>
>>> is_array_like([1, 2, 3])
True
>>> is_array_like((1, 2, 3))
True
>>> is_array_like(np.array([1, 2, 3]))
True
>>> is_array_like(42)
False

Notes

  • Checks PyTorch tensors lazily to avoid import overhead

  • Does not include pandas/xarray to keep scitex-core lightweight

  • For pandas/xarray support, use the full scitex package

scitex_core.types.is_list_of_type(obj, types)[source]

Check if obj is a list where all elements are of one of the specified types.

This is an alias for is_listed_X with a more conventional name.

Parameters:
  • obj (Any) – Object to check

  • types (type or list/tuple of types) – Type or types to check against

Returns:

True if obj is a list and all elements are of one of the specified types

Return type:

bool

Examples

>>> from scitex_core.types import is_list_of_type
>>>
>>> numbers = [1, 2, 3, 4]
>>> is_list_of_type(numbers, int)
True
>>>
>>> mixed = [1, 2.0, "3"]
>>> is_list_of_type(mixed, (int, float, str))
False

See also

is_listed_X

Original function name

scitex_core.types.is_listed_X(obj, types)[source]

Check if obj is a list where all elements are of one of the specified types.

Parameters:
  • obj (Any) – Object to check

  • types (type or list/tuple of types) – Type or types to check against

Returns:

True if obj is a list and all elements are of one of the specified types

Return type:

bool

Examples

>>> from scitex_core.types import is_listed_X
>>>
>>> obj = [3, 2, 1, 5]
>>> is_listed_X(obj, int)  # Returns True
>>> is_listed_X(obj, (int, float))  # Returns True
>>> is_listed_X(obj, str)  # Returns False
>>>
>>> mixed = [1, "a", 3]
>>> is_listed_X(mixed, int)  # Returns False
>>>
>>> floats = [1.0, 2.0, 3.0]
>>> is_listed_X(floats, float)  # Returns True

Notes

  • Returns False if obj is not a list

  • Returns False if any element doesn’t match the specified types

  • Empty lists return True