dispatch

earthkit.utils.decorators.dispatch(func: Callable, match: int | str = 0, xarray: bool = True, fieldlist: bool = True, array: bool = True, array_like: bool = False)[source]

Decorator to dispatch function calls based on input data types.

The dispatch will attempt to route the call to the appropriate implementation based on the type of the specified argument. The implementations are assumed to live in submodules named after the data type (e.g., .xarray, .fieldlist, .array) with the same function name as the toplevel function.

This wrapper should be applied inline as:

def func(…):

return dispatch(func, match=…, xarray=…, fieldlist=…, array=…, array_like=…)(…)

Parameters:
  • func (function) – The toplevel function to be wrapped.

  • match (int or str) – The index or name of the argument to check for dispatching. Default is 0 (the first argument).

  • xarray (bool) – Whether to include the xarray dispatcher. Default is True.

  • fieldlist (bool) – Whether to include the FieldList dispatcher. Default is True.

  • array (bool) – Whether to include the array dispatcher. Default is True.

  • array_like (bool) – Whether to include the array-like dispatcher. Default is False.

Returns:

The decorated function with dispatching capability.

Return type:

function