empty_array#

paramcheckup.numpy_arrays.empty_array(array, param_name, kind, kind_name, stacklevel=4, error=True)[source]#

This function checks whether a numpy array is empty.

Parameters:
arraynumpy array

The numpy array to check for emptiness;

param_namestr

The name of the parameter that received the variable array;

kindstr

The object where param_name is applied (function, method, class, etc.);

kind_namestr

The name of the object kind;

stacklevelint, optional

The stacking level (default is 4);

errorbool, optional

Whether to display error text (True, default) or not (False);

Returns:
outputTrue

If the array is NOT empty;

raisesValueError

If the array IS empty;

Examples

>>> from paramcheckup import numpy_arrays
>>> import numpy as np
>>> data = np.array([1, 2, 3, 4, 5])
>>> output = numpy_arrays.empty_array(
    array=data,
    param_name="x_data",
    kind="function",
    kind_name="ttest",
    stacklevel=3,
    error=True,
)
>>> print(output)
True
>>> from paramcheckup import numpy_arrays
>>> import numpy as np
>>> data = np.array([])
>>> output = numpy_arrays.empty_array(
    array=data,
    param_name="x_data",
    kind="function",
    kind_name="ttest",
    stacklevel=3,
    error=False,
)
UserWarning at line 4: The `x_data` in function `ttest` cannot be an empty array.