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
View on GitHub
Show/Hide source
| 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 = []
root = str(Path(__file__).parent.parent) # yohou package
# Ignore deprecation warnings triggered at import time and from walking
# packages
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=FutureWarning)
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 name, func in functions if not name.startswith("_")]
all_functions.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), key=itemgetter(0))
|