sidpy.hdf.dtype_utils.validate_dtype

sidpy.hdf.dtype_utils.validate_dtype(dtype)[source]

Checks the provided object to ensure that it is a valid dtype that can be written to an HDF5 file. Raises a type error if invalid. Returns True if the object passed the tests

Parameters:

dtype (object) – Object that is hopefully a h5py.Datatype, or numpy.dtype object

Returns:

status – True if the object was a valid data-type

Return type:

bool

Examples

>>> import numpy as np
>>> import sidpy
>>> for item in [np.float16, np.complex64, np.uint8, np.int16]:
>>>     print('Is {} a valid dtype? : {}'.format(item, sidpy.dtype_utils.validate_dtype(item)))
Is <class 'numpy.float16'> a valid dtype? : True
Is <class 'numpy.complex64'> a valid dtype? : True
Is <class 'numpy.uint8'> a valid dtype? : True
Is <class 'numpy.int16'> a valid dtype? : True

# This function is especially useful on compound or structured data types: >>> struct_dtype = np.dtype({‘names’: [‘r’, ‘g’, ‘b’], >>> ‘formats’: [np.float32, np.uint16, np.float64]}) >>> print(‘Is {} a valid dtype? : {}’.format(struct_dtype, sidpy.dtype_utils.validate_dtype(struct_dtype))) Is [(‘r’, ‘<f4’), (‘g’, ‘<u2’), (‘b’, ‘<f8’)] a valid dtype? : True