From 14ae29bf3c631b85b875a20bc968e1580d0905f0 Mon Sep 17 00:00:00 2001 From: Florez Ospina Juan Felipe Date: Fri, 26 Apr 2024 12:54:41 +0200 Subject: [PATCH] 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. --- src/hdf5_vis.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/hdf5_vis.py b/src/hdf5_vis.py index 1fa6ab5..b5c8dc3 100644 --- a/src/hdf5_vis.py +++ b/src/hdf5_vis.py @@ -75,19 +75,13 @@ def make_dtype_yaml_compatible(value): print('Yaml-compatible data-type was not found. Value has been set to Nan.') value = np.nan elif isinstance(value, np.ndarray): - if np.issubdtype(value.dtype, np.string_): - value = value.astype(str).tolist() - elif np.issubdtype(value.dtype, np.integer): - value = value.astype(int).tolist() + if np.issubdtype(value.dtype, np.string_) or np.issubdtype(value.dtype, np.generic): + 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) : + 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): - value = 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') + value = [float(item) for item in value] if len(value)>1 else float(value[0]) # value.astype(float).tolist() + except: print('Yaml-compatible data-type was not found. Value has been set to Nan.') value = np.nan