pyvista_validation.check.check_subdtype

Contents

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

dtype object (or object coercible to one) or an array-like object. If array-like, the dtype of the array is used.

base_dtypeDTypeLike | Sequence[DTypeLike]

dtype-like object or a sequence of dtype-like objects. The input_obj must be a subtype of this value. If a sequence, input_obj must be a subtype of at least one of the specified dtypes.

namestr, default: “Input”

Variable name to use in the error messages if any are raised.

Returns:
object

The input, unchanged.

Raises:
TypeError

If input_obj is not a subtype of base_dtype.

Examples

Check if float is a subtype of np.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)