pyvista_validation.check.check_subdtype#
- pyvista_validation.check.check_subdtype(input_obj: npt.DTypeLike | _ArrayLikeOrScalar[NumberType], /, base_dtype: npt.DTypeLike | tuple[npt.DTypeLike, ...] | list[npt.DTypeLike], *, name: str = 'Input') None#
Check if an input’s data-type is a subtype of another data-type or data-types.
- Parameters:
- input_objfloat | ArrayLike[float] | numpy.typing.DTypeLike
dtypeobject (or object coercible to one) or an array-like object. If array-like, thedtypeof the array is used.- base_dtypenumpy.typing.DTypeLike | Sequence[numpy.typing.DTypeLike]
dtype-like object or a sequence ofdtype-like objects. Theinput_objmust be a subtype of this value. If a sequence,input_objmust be a subtype of at least one of the specifieddtypes.- namestr, default: “Input”
Variable name to use in the error messages if any are raised.
- Raises:
- TypeError
If
input_objis not a subtype ofbase_dtype.
See also
Examples
Check if
floatis a subtype ofnp.floating.>>> import numpy as np >>> from pyvista_validation import check_subdtype >>> check_subdtype(float, np.floating)
Check from multiple allowable
dtypes.>>> check_subdtype(int, [np.integer, np.floating])
Check an array’s
dtype.>>> array = np.array([1, 2, 3], dtype='uint8') >>> check_subdtype(array, np.integer)