is_between_a_and_b#
- paramcheckup.numbers.is_between_a_and_b(number, lower, upper, param_name, kind, kind_name, inclusive=True, stacklevel=4, error=True)[source]#
This function checks whether a number (number) is within the range (open or closed) lower and upper.
- Parameters:
- numberint or float
The number that needs to be checked;
- lowerint or float
The lower bound;
- upperint or float
The upper bound;
- param_namestr
The name of the parameter that received the variable number;
- kindstr
The object where param_name is applied (function, method, class, etc.);
- kind_namestr
The name of the object kind;
- inclusivebool, optional
Specify whether the boundaries should be open (False) or closed (True, default);
- stacklevelint, optional
The stacking level (default is
4);- errorbool, optional
Whether to display error text (True, default) or not (False);
- Returns:
- outputTrue
If number IN [a;b] (or (a;b)) interval;
- raisesValueError
If number NOT in [a;b] (or (a;b)) interval;
Notes
If lower is greater than upper, the function automatically inverts the values to make mathematical sense.
Examples
Checking if the significance level is a number between 0 and 1:
>>> from paramcheckup import numbers >>> output = numbers.is_between_a_and_b( number=0, lower=0, upper=1, param_name="alpha", kind="function", kind_name="ttest", stacklevel=3, error=False, ) >>> print(output) True
In some cases the lower and upper limits must be opened. To disallow closed ranges, simply pass parameter inclusive=False:
>>> from paramcheckup import numbers >>> output = numbers.is_between_a_and_b( number=0.0, lower=0, upper=1, param_name="alpha", kind="function", kind_name="ttest", inclusive=False, stacklevel=3, error=False, ) UserWarning at line 3: The value of `alpha` in function `ttest` must be within the range of `0 < alpha < 1`, but it is `0`.
Another example with an error being reported, but with inclusive=True:
>>> from paramcheckup import numbers >>> output = numbers.is_between_a_and_b( number=-0.35, lower=0, upper=1, param_name="alpha", kind="function", kind_name="ttest", stacklevel=3, error=False, ) UserWarning at line 3: The value of `alpha` in function `ttest` must be within the range of `0 <= alpha <= 1`, but it is `-0.35`.