Validate and standardize array-like input.
Actively maintained. Last release 2 months ago, commits in 12 of the last 26 weeks. A safe choice.
pip install pyvista-validationpyvista-validation
Validate and standardize array-like input.
These are the input validation functions developed for PyVista, extracted into a standalone package so any project can use them. NumPy is the only required dependency: PyVista is not needed, and VTK and SciPy are optional.
The functions are useful when writing Python methods that accept flexible array-like input, wrapping VTK, or anywhere you want one standard representation out of many possible inputs.
Warning — The API of this package is unstable and likely to change between minor versions (for example
0.1.0to0.2.0). Pin the exact version you depend on, for examplepyvista-validation==0.1.0.
Installation
pip install pyvista-validation
VTK and SciPy are only needed to validate their own object types, so they ship as extras:
pip install pyvista-validation[vtk] # accept vtkMatrix3x3, vtkMatrix4x4, vtkTransform
pip install pyvista-validation[scipy] # accept scipy.spatial.transform.Rotation
pip install pyvista-validation[all] # both
Neither is imported unless you actually pass one of their objects in.
The wheels carry a C extension that runs the checks; the package works the same without it,
from the source distribution or with PYVISTA_VALIDATION_ACCELERATE=false in the environment.
Two families of function
A check function:
- Performs a simple validation on a single input variable.
- Raises an error if the check fails due to invalid input.
- Does not modify its input, and returns it unchanged, typed as what the check established, so a check can be used inline.
A validate function:
- Uses
checkfunctions to check the type and/or value of input arguments. - Applies optional constraints -- for example input or output must have a specific length, shape, type, data-type, etc.
- Accepts many different input types or values and standardizes the output as a single representation with known properties.
Usage
validate functions return a standard representation:
>>> import numpy as np
>>> from pyvista_validation import validate_array3
>>> from pyvista_validation import validate_arrayNx3
>>> from pyvista_validation import validate_data_range
>>> validate_array3([1, 2, 3])
array([1, 2, 3])
>>> validate_arrayNx3([[1, 2, 3], [4, 5, 6]])
array([[1, 2, 3],
[4, 5, 6]])
>>> validate_data_range([0, 1])
(0, 1)