diff --git a/utils/g5505_utils.py b/utils/g5505_utils.py index 5401232..36c5d93 100644 --- a/utils/g5505_utils.py +++ b/utils/g5505_utils.py @@ -326,17 +326,23 @@ def to_serializable_dtype(value): if value.dtype.names: value = {field: to_serializable_dtype(value[field]) for field in value.dtype.names} else: - # Handling regular array NumPy types - if np.issubdtype(value.dtype, np.bytes_): + # Handling regular array NumPy types with assumption of unform dtype accross array elements + # TODO: evaluate a more general way to check for individual dtypes + if isinstance(value[0], bytes): + # Decode bytes value = [item.decode('utf-8') for item in value] if len(value) > 1 else value[0].decode('utf-8') - elif np.issubdtype(value.dtype, np.unicode_): + elif isinstance(value[0], str): + # Already a string type value = [str(item) for item in value] if len(value) > 1 else str(value[0]) - elif np.issubdtype(value.dtype, np.integer): + elif isinstance(value[0], int): + # Integer type value = [int(item) for item in value] if len(value) > 1 else int(value[0]) - elif np.issubdtype(value.dtype, np.floating): + elif isinstance(value[0], float): + # Floating type value = [float(item) for item in value] if len(value) > 1 else float(value[0]) else: print('Yaml-compatible data-type was not found. Value has been set to NaN.') + print("Debug: value.dtype is", value.dtype) value = np.nan except Exception as e: