is_float_or_int#

paramcheckup.numbers.is_float_or_int(number, param_name, kind, kind_name, stacklevel=4, error=True)[source]#

This function checks whether a variable value is of the int or float type.

Parameters:
numberint or float

The number that needs to be checked;

param_namestr

The name of the parameter that received the variable

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 variable number IS of the int or float type;

raisesTypeError

If variable number is NOT of the int or float type;

Notes

The following types are considered to be True:

  • int;

  • float;

  • np.floating;

  • np.integer;

  • np.uint;

Examples

>>> from paramcheckup import numbers
>>> result = numbers.is_float_or_int(
    number=2,
    param_name="hypotenuse",
    kind="function",
    kind_name="pitagoras",
    stacklevel=3,
    error=True,
)
>>>  print(result)
True
>>> from paramcheckup import numbers
>>> result = numbers.is_float_or_int(
    number="2",
    param_name="hypotenuse",
    kind="function",
    kind_name="pitagoras",
    stacklevel=3,
    error=False,
)
UserWarning at line 2: The `hypotenuse` in function `pitagoras` must be of type `int` or `float`, but its type is `str`.