Utilities
- pylena.check_type(func=None, ind=0, wanted_types=[])
Decorator to check the type of an argument
- Parameters:
func – The function to be decorated
ind – The index of the argument to be checked in the function
wanted_types – The accepted type for the argument
- Raises:
ValueError – If ind is superior or equal to the number of argument or if the type is not accepted by the function
Example
@check_type(ind=0, wanted_types=[str]) def foo(name): return "My name is {}".format(name)
- pylena.check_numpy_array(func=None, ind=0, dtypes=[], ndims=[])
Decorator to check that the input numpy array dtype is accepted by a function
- Parameters:
func – The function to be decorated
ind – The index of the argument in the function
dtypes – The list of accepted dtypes
ndims – The list of accepted number of dimensions
- Raises:
ValueError – If ind is superior or equal to the number of argument, the argument pointed by ind is not a numpy array, if the dtype is not accepted or if the number of dimensions is incorrect.
Example
@check_numpy_array(ind=0, dtypes=[np.uint8], ndims=[2]) def transpose_uint8(a): return a.T