erlab.utils.misc

Utilities that don’t fit in any other category.

Functions

emit_user_level_warning(message[, category])

Emit a warning at the user level by inspecting the stack trace.

is_interactive()

Check if the code is running in an interactive environment.

is_sequence_of(val, element_type)

Check if the given object is a sequence of elements of the specified type.

open_in_file_manager(path)

Reveal a path in the system's file manager.

Classes

LazyImport(module_name[, err_msg])

Lazily import a module when an attribute is accessed.

class erlab.utils.misc.LazyImport(module_name, err_msg=None)[source]

Bases: object

Lazily import a module when an attribute is accessed.

Used to delay the import of a module until it is actually needed.

Parameters:
  • module_name (str) – The name of the module to be imported lazily.

  • err_msg (str, optional) – If present, this message will be displayed in the ImportError raised when the accessed module is not found.

Examples

>>> np = LazyImport("numpy")
>>> np.array([1, 2, 3])
array([1, 2, 3])
erlab.utils.misc.emit_user_level_warning(message, category=None)[source]

Emit a warning at the user level by inspecting the stack trace.

erlab.utils.misc.is_interactive()[source]

Check if the code is running in an interactive environment.

Returns:

boolTrue if the code is running in an interactive environment (IPython), False otherwise.

Return type:

bool

erlab.utils.misc.is_sequence_of(val, element_type)[source]

Check if the given object is a sequence of elements of the specified type.

Parameters:
  • val (Any) – The object to check.

  • element_type (type[TypeVar(_T)]) – The type of elements that the sequence should contain.

Returns:

boolTrue if val is a sequence and all elements in the sequence are of type element_type, False otherwise.

Return type:

TypeGuard[Sequence[_T]]

Examples

>>> is_sequence_of([1, 2, 3], int)
True
>>> is_sequence_of([1, 2, "3"], int)
False
erlab.utils.misc.open_in_file_manager(path)[source]

Reveal a path in the system’s file manager.

Parameters:

path (str | PathLike) – Path to the file or folder.