pyvista_validation.check.check_subdtype#
- pyvista_validation.check.check_subdtype(input_obj, /, base_dtype, *, name='Input')#
Check if an input’s data-type is a subtype of another data-type or data-types.
- Parameters:
- input_objfloat | ArrayLikeFloat | DTypeLike
dtypeobject (or object coercible to one) or an array-like object. If array-like, thedtypeof the array is used.- base_dtypeDTypeLike | Sequence[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.
- Returns:
- object
The input, unchanged.
- 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) <class 'float'>
Check from multiple allowable
dtypes.>>> check_subdtype(int, [np.integer, np.floating]) <class 'int'>
Check an array’s
dtype.>>> array = np.array([1, 2, 3], dtype='uint8') >>> check_subdtype(array, np.integer) array([1, 2, 3], dtype=uint8)