cast#

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

This function attempts to transform an array into a ndim numpy array.

Parameters:
arraylist, tuple or pd.Series

The variable that will be converted into a ndim numpy array;

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;

ndimint, optional

The number of dimentions that array must have;

stacklevelint, optional

The stacking level (default is 4);

errorbool, optional

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

Returns:
arraynumpy array

One dimension numpy array;

raisesValueError

If it was not possible to transform array into a numpy array;

Examples

>>> from paramcheckup import numpy_arrays
>>> x_exp = [1, 2, 3, 4]
>>> x_exp = numpy_arrays.cast(
    array=x_exp,
    param_name="x",
    kind="function",
    kind_name="ttest",
    ndim=1,
    stacklevel=3,
    error=True,
)
>>> print(x_exp)
[1 2 3 4]
>>> from paramcheckup import numpy_arrays
>>> x_exp = [1, 2, 3, 4]
>>> x_exp = numpy_arrays.cast(
    array=x_exp,
    param_name="x",
    kind="function",
    kind_name="ttest",
    ndim=2,
    stacklevel=3,
    error=False,
)
UserWarning at line 3: The array generated for `x` in function `ttest` contains `1` dimensions, but it should contain `2` dimensions.