Skip to main content

custom_lru_cache

custom_lru_cache(
    maxsize=128,
    typed=False,
)
Least-recently-used cache decorator. If maxsize is set to None, the LRU features are disabled and the cache can grow without bound. If typed is True, arguments of different types will be cached separately. For example, f(decimal.Decimal(“3.0”)) and f(3.0) will be treated as distinct calls with distinct results. Some types such as str and int may be cached separately even when typed is false. Arguments to the cached function must be hashable. View the cache statistics named tuple (hits, misses, maxsize, currsize) with f.cache_info(). Clear the cache and statistics with f.cache_clear(). Access the underlying function with f.wrapped. See: https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)

remove_nans

remove_nans(
    func: Callable,
) ‑> Callable
Decorator that cleans all numpy array arguments (except self) by removing NaN values. This decorator processes each numpy array argument passed to the decorated function by:
  1. Dropping rows that are entirely NaNs in any of the arrays.
  2. Dropping columns (after row filtering) that contain any NaNs in any of the arrays.
All numpy array arguments must have the same shape, otherwise a ValueError is raised. Parameters:
NameTypeDefaultDescription
functp.Callable--The function whose numpy array arguments will be cleaned.
Raises:
TypeDescription
ValueErrorIf not all numpy array arguments have the same shape.
Returns:
TypeDescription
tp.CallableA wrapped version of the input function with the NaNs cleaning logic applied.

filter_config

filter_config(
    func,
)
A decorator to filter a list of Feature objects based on search terms from the function signature. The decorated method must take a search parameter (str or list of str) and have access to self.feature. It filters the list by searching within id (case-sensitive), study_name, and timeframe (case-insensitive) attributes. Supports substring matching and prefix matching with trailing *. Returns:
TypeDescription
tp.CallableDecorated function returning filtered list of Feature objects.

catch_exceptions

catch_exceptions(
    cancel_on_failure: bool = False,
) ‑> Callable
Guard against schedule exceptions. Schedule library doesn’t catch exceptions that happen during job execution. Therefore any exceptions thrown during job execution will bubble up and interrupt schedule’s run_xyz function. Parameters:
NameTypeDefaultDescription
cancel_on_failureboolFalseIf True, the job will be cancelled on failure, returning schedule.CancelJob. If False, the job will continue running even if an exception occurs. Defaults to False.
Returns:
TypeDescription
tp.CallableDecorated function allowing to catch exceptions.

deprecated

deprecated(
    reason: str = 'This function is deprecated and has been disabled.',
) ‑> Callable
Decorator to mark functions as deprecated and prevent their use. When the decorated function is called, a DeprecationWarning is issued, and a RuntimeError is raised to stop execution. Parameters:
NameTypeDefaultDescription
reasonstrThis...A message indicating why the function is deprecated or what to use instead. Defaults to “This function is deprecated and has been disabled.”
Raises:
TypeDescription
RuntimeErrorAlways raised when the decorated function is called to indicate it is disabled.
Returns:
TypeDescription
callableA wrapper function that issues a warning and raises an error when called.
Examples:
>>> @deprecated("Use `new_function` instead.")
... def old_function():
...     pass
>>> old_function()
# DeprecationWarning: old_function is deprecated: Use `new_function` instead.
# RuntimeError: Use `new_function` instead.