> ## Documentation Index
> Fetch the complete documentation index at: https://systematica.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Decorators

> systematica.utils.decorators

## `custom_lru_cache`

```python theme={null}
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)](https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_\(LRU\))

## `remove_nans`

```python theme={null}
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**:

| Name   | Type          | Default | Description                                               |
| ------ | ------------- | ------- | --------------------------------------------------------- |
| `func` | `tp.Callable` | `--`    | The function whose numpy array arguments will be cleaned. |

**Raises**:

| Type         | Description                                             |
| ------------ | ------------------------------------------------------- |
| `ValueError` | If not all `numpy` array arguments have the same shape. |

**Returns**:

| Type          | Description                                                                     |
| ------------- | ------------------------------------------------------------------------------- |
| `tp.Callable` | A wrapped version of the input function with the `NaNs` cleaning logic applied. |

## `filter_config`

```python theme={null}
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**:

| Type          | Description                                                      |
| ------------- | ---------------------------------------------------------------- |
| `tp.Callable` | Decorated function returning filtered list of `Feature` objects. |

## `catch_exceptions`

```python theme={null}
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**:

| Name                | Type   | Default | Description                                                                                                                                                                  |
| ------------------- | ------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `cancel_on_failure` | `bool` | `False` | If `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**:

| Type          | Description                                      |
| ------------- | ------------------------------------------------ |
| `tp.Callable` | Decorated function allowing to catch exceptions. |

## `deprecated`

```python theme={null}
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**:

| Name     | Type  | Default   | Description                                                                                                                                  |
| -------- | ----- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| `reason` | `str` | `This...` | A message indicating why the function is deprecated or what to use instead. Defaults to "This function is deprecated and has been disabled." |

**Raises**:

| Type           | Description                                                                     |
| -------------- | ------------------------------------------------------------------------------- |
| `RuntimeError` | Always raised when the decorated function is called to indicate it is disabled. |

**Returns**:

| Type       | Description                                                               |
| ---------- | ------------------------------------------------------------------------- |
| `callable` | A wrapper function that issues a warning and raises an error when called. |

**Examples**:

```python theme={null}
>>> @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.
```
