Implement skipping in convert_attrdict_to_np_structured_array(attr_value: dict) when dictionary values are not scalar. This ensures compatible values are transfered while the rest simply dicarded.
This commit is contained in:
@ -3,4 +3,5 @@ exclude_paths:
|
||||
- .ipynb_checkpoints
|
||||
- .renku
|
||||
- .git
|
||||
# - params
|
||||
# - params
|
||||
- .Trash
|
@ -237,21 +237,27 @@ def convert_attrdict_to_np_structured_array(attr_value: dict):
|
||||
|
||||
Returns
|
||||
-------
|
||||
new_attr_value : ndarray or str
|
||||
Numpy structured array with UTF-8 encoded fields. Returns 'missing' if
|
||||
new_attr_value : ndarray
|
||||
Numpy structured array with UTF-8 encoded fields. Returns np.array(['missing'], dtype=[str]) if
|
||||
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 = []
|
||||
values_list = []
|
||||
max_length = max(len(str(attr_value[key])) for key in attr_value.keys())
|
||||
for key in attr_value.keys():
|
||||
if key != 'rename_as':
|
||||
for key, val in attr_value.items():
|
||||
# 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}'))
|
||||
values_list.append(attr_value[key])
|
||||
else:
|
||||
print(f"Skipping unsupported type for key {key}: {type(val)}")
|
||||
if values_list:
|
||||
new_attr_value = np.array([tuple(values_list)], dtype=dtype)
|
||||
else:
|
||||
new_attr_value = 'missing'
|
||||
new_attr_value = np.array(['missing'], dtype=[str])
|
||||
|
||||
return new_attr_value
|
||||
|
||||
|
Reference in New Issue
Block a user