skneuromsi.utils.ddtype_tools module

Utilities for working with data types and memory usage in Python objects.

skneuromsi.utils.ddtype_tools.is_astypeable(obj)[source]

Check if an object support the message astype.

skneuromsi.utils.ddtype_tools.is_class_astypeable(cls)[source]

Check if object of class support the message astype.

skneuromsi.utils.ddtype_tools.single_dtype(obj)[source]

Check if an object has an attribute dtype.

skneuromsi.utils.ddtype_tools.single_dtype_class(cls)[source]

Check if object of class has an attribute dtype.

skneuromsi.utils.ddtype_tools.multiple_dtype(obj)[source]

Check if an object has an attribute dtypes.

skneuromsi.utils.ddtype_tools.multiple_dtype_class(cls)[source]

Check if object of class has an attribute dtypes.

skneuromsi.utils.ddtype_tools.deep_astype(obj, dtype=None)[source]

Recursively cast the data type of an object and its nested objects.

Parameters:
  • obj (object) – The object to cast.

  • dtype (data type, optional) – The data type to cast to. If None (default), the object is returned as is.

Returns:

The object with the new data type.

Return type:

object

skneuromsi.utils.ddtype_tools.deep_dtypes(obj, *, root='root', max_deep=2, memory_usage=False)[source]

Get the data types and optionally the memory usage of an object and its nested objects.

Parameters:
  • obj (object) – The object to get the data types and memory usage for.

  • root (str, optional) – The name of the root object (default is “root”).

  • max_deep (int, optional) – The maximum depth of recursion (default is 2).

  • memory_usage (bool, optional) – Whether to calculate the memory usage (default is False).

Returns:

If memory_usage is True, a dictionary with keys representing the nested objects and values representing their data types and memory usage. If memory_usage is False, a tuple with the nested data types.

Return type:

tuple or dict