Renamed make_dtype_yaml_compatible func as to_serializable_dtype func

This commit is contained in:
2024-09-25 16:36:50 +02:00
parent df2f7b3de6
commit 10554fc41e

View File

@ -67,7 +67,20 @@ def display_group_hierarchy_on_a_treemap(filename: str):
#pio.write_image(fig,file_name + ".png",width=800,height=600,format='png')
#
def make_dtype_yaml_compatible(value):
def to_serializable_dtype(value):
"""Transform value's dtype into YAML/JSON compatible dtype
Parameters
----------
value : _type_
_description_
Returns
-------
_type_
_description_
"""
try:
if isinstance(value, np.generic):
if np.issubdtype(value.dtype, np.bytes_):
@ -82,7 +95,7 @@ def make_dtype_yaml_compatible(value):
elif isinstance(value, np.ndarray):
# Handling structured array types (with fields)
if value.dtype.names:
value = {field: make_dtype_yaml_compatible(value[field]) for field in 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_):
@ -121,11 +134,10 @@ def construct_attributes_dict(attrs_obj):
if is_structured_array(value):
#for subattr in value.dtype.names:
#attr_dict[key][subattr] = make_dtype_yaml_compatible(value[subattr])
attr_dict[key] = make_dtype_yaml_compatible(value)
attr_dict[key] = to_serializable_dtype(value)
else:
value = make_dtype_yaml_compatible(value)
attr_dict[key] = {"rename_as" : key,
"value" : value
"value" : to_serializable_dtype(value)
}
#if isinstance(value,str):