|
|
|
@@ -237,21 +237,27 @@ def convert_attrdict_to_np_structured_array(attr_value: dict):
|
|
|
|
|
|
|
|
|
|
|
|
Returns
|
|
|
|
Returns
|
|
|
|
-------
|
|
|
|
-------
|
|
|
|
new_attr_value : ndarray or str
|
|
|
|
new_attr_value : ndarray
|
|
|
|
Numpy structured array with UTF-8 encoded fields. Returns 'missing' if
|
|
|
|
Numpy structured array with UTF-8 encoded fields. Returns np.array(['missing'], dtype=[str]) if
|
|
|
|
the input dictionary is empty.
|
|
|
|
the input dictionary is empty.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
if not isinstance(attr_value,dict):
|
|
|
|
|
|
|
|
raise ValueError(f'Input paremeter {attr_value} must be a dictionary of scalar values.')
|
|
|
|
|
|
|
|
|
|
|
|
dtype = []
|
|
|
|
dtype = []
|
|
|
|
values_list = []
|
|
|
|
values_list = []
|
|
|
|
max_length = max(len(str(attr_value[key])) for key in attr_value.keys())
|
|
|
|
max_length = max(len(str(attr_value[key])) for key in attr_value.keys())
|
|
|
|
for key in attr_value.keys():
|
|
|
|
for key, val in attr_value.items():
|
|
|
|
if key != 'rename_as':
|
|
|
|
# Verify if 'rename_as' is still used in metadata revision
|
|
|
|
|
|
|
|
if key != 'rename_as' and isinstance(val, (int, float, str)):
|
|
|
|
dtype.append((key, f'S{max_length}'))
|
|
|
|
dtype.append((key, f'S{max_length}'))
|
|
|
|
values_list.append(attr_value[key])
|
|
|
|
values_list.append(attr_value[key])
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
print(f"Skipping unsupported type for key {key}: {type(val)}")
|
|
|
|
if values_list:
|
|
|
|
if values_list:
|
|
|
|
new_attr_value = np.array([tuple(values_list)], dtype=dtype)
|
|
|
|
new_attr_value = np.array([tuple(values_list)], dtype=dtype)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
new_attr_value = 'missing'
|
|
|
|
new_attr_value = np.array(['missing'], dtype=[str])
|
|
|
|
|
|
|
|
|
|
|
|
return new_attr_value
|
|
|
|
return new_attr_value
|
|
|
|
|
|
|
|
|
|
|
|
|