plima.utils.validators#

Validation helpers for numerical inputs.

Functions

as_finite_float_array(values, *, name)

Return values as a finite NumPy float array.

as_float_array(values, *, name)

Return values as a NumPy float array.

validate_finite(values, *, name)

Check that all values are finite.

validate_fraction(values, *, name)

Check that all values are fractions between zero and one.

validate_greater_than(values, *, threshold, name)

Check that all values are greater than a threshold.

validate_non_negative(values, *, name)

Check that all values are non negative.

validate_positive(values, *, name)

Check that all values are positive.

plima.utils.validators.as_finite_float_array(values, *, name)[source]#

Return values as a finite NumPy float array.

Parameters:
  • values (ArrayLike) – Input values to convert and check.

  • name (str) – Name of the input used in error messages.

Returns:

Input values converted to a finite float array.

Raises:

ValueError – If any value is not finite.

Return type:

ndarray[tuple[Any, …], dtype[float64]]

plima.utils.validators.as_float_array(values, *, name)[source]#

Return values as a NumPy float array.

Parameters:
  • values (ArrayLike) – Input values to convert.

  • name (str) – Name of the input used in error messages.

Returns:

Input values converted to a float array.

Raises:

ValueError – If the input cannot be converted to floats.

Return type:

ndarray[tuple[Any, …], dtype[float64]]

plima.utils.validators.validate_finite(values, *, name)[source]#

Check that all values are finite.

Parameters:
  • values (ArrayLike) – Input values to check.

  • name (str) – Name of the input used in error messages.

Raises:

ValueError – If any value is NaN or infinite.

Return type:

None

plima.utils.validators.validate_fraction(values, *, name)[source]#

Check that all values are fractions between zero and one.

Parameters:
  • values (ArrayLike) – Input values to check.

  • name (str) – Name of the input used in error messages.

Raises:

ValueError – If any value is outside the closed interval from zero to one.

Return type:

None

plima.utils.validators.validate_greater_than(values, *, threshold, name)[source]#

Check that all values are greater than a threshold.

Parameters:
  • values (ArrayLike) – Input values to check.

  • threshold (float) – Lower allowed bound.

  • name (str) – Name of the input used in error messages.

Raises:

ValueError – If any value is less than or equal to threshold.

Return type:

None

plima.utils.validators.validate_non_negative(values, *, name)[source]#

Check that all values are non negative.

Parameters:
  • values (ArrayLike) – Input values to check.

  • name (str) – Name of the input used in error messages.

Raises:

ValueError – If any value is negative.

Return type:

None

plima.utils.validators.validate_positive(values, *, name)[source]#

Check that all values are positive.

Parameters:
  • values (ArrayLike) – Input values to check.

  • name (str) – Name of the input used in error messages.

Raises:

ValueError – If any value is less than or equal to zero.

Return type:

None