Corrected parsing problem from hdf5 to yaml attribute. Single element arrays are now represented as a scalar as opposed to a list with a single element.

This commit is contained in:
2024-04-26 12:54:41 +02:00
parent cefa2219e1
commit 14ae29bf3c

View File

@ -75,19 +75,13 @@ def make_dtype_yaml_compatible(value):
print('Yaml-compatible data-type was not found. Value has been set to Nan.') print('Yaml-compatible data-type was not found. Value has been set to Nan.')
value = np.nan value = np.nan
elif isinstance(value, np.ndarray): elif isinstance(value, np.ndarray):
if np.issubdtype(value.dtype, np.string_): if np.issubdtype(value.dtype, np.string_) or np.issubdtype(value.dtype, np.generic):
value = value.astype(str).tolist() value = [str(item) for item in value] if len(value)>1 else str(value[0]) # value.astype(str).tolist()
elif np.issubdtype(value.dtype, np.integer): elif np.issubdtype(value.dtype, np.integer) :
value = value.astype(int).tolist() value = [int(item) for item in value] if len(value)>1 else int(value[0]) # value.astype(int).tolist()
elif np.issubdtype(value.dtype, np.floating): elif np.issubdtype(value.dtype, np.floating):
value = value.astype(float).tolist() value = [float(item) for item in value] if len(value)>1 else float(value[0]) # value.astype(float).tolist()
elif np.issubdtype(value.dtype, np.generic):
value = value.astype(str).tolist()
#elif isinstance(value,(int,float,str)):
#print('Yaml-compatible data-type was not found. Value has been set to Nan.')
#value = np.nan
#print('leave value as is')
except: except:
print('Yaml-compatible data-type was not found. Value has been set to Nan.') print('Yaml-compatible data-type was not found. Value has been set to Nan.')
value = np.nan value = np.nan