Skip to content

all_functions

yohou.utils.all_functions()

Get a list of all functions from yohou.

Returns

Name Type Description
functions list of tuples

List of (name, function), where name is the function name as string and function is the actual function.

Examples

>>> from yohou.utils.discovery import all_functions
>>> functions = all_functions()

See Also

Source Code

Source code in src/yohou/utils/discovery.py
def all_functions() -> list[tuple[str, object]]:
    """Get a list of all functions from `yohou`.

    Returns
    -------
    functions : list of tuples
        List of (name, function), where ``name`` is the function name as
        string and ``function`` is the actual function.

    Examples
    --------
    >>> from yohou.utils.discovery import all_functions
    >>> functions = all_functions()

    See Also
    --------
    - [`all_estimators`][yohou.utils.discovery.all_estimators] : Get all estimator classes from yohou.
    - [`all_displays`][yohou.utils.discovery.all_displays] : Get all display classes from yohou.
    """
    all_functions_list = []
    root = str(Path(__file__).parent.parent)  # yohou package
    with warnings.catch_warnings():
        _ignore_third_party_future_warnings()
        for _, module_name, _ in pkgutil.walk_packages(path=[root], prefix="yohou."):
            module_parts = module_name.split(".")
            if any(part in _MODULE_TO_IGNORE for part in module_parts):
                continue

            try:
                module = import_module(module_name)
            except ImportError:
                continue
            functions = inspect.getmembers(module, _is_checked_function)
            functions = [(func.__name__, func) for _, func in functions]
            all_functions_list.extend(functions)

    # drop duplicates, sort for reproducibility
    # itemgetter is used to ensure the sort does not extend to the 2nd item of
    # the tuple
    return sorted(set(all_functions_list), key=itemgetter(0))