Skip to content

Utilities

Dataset

oqd_dataschema.utils

dict_to_structured(data)

Source code in oqd-dataschema/src/oqd_dataschema/utils.py
def dict_to_structured(data):
    data_dtype = _dtype_from_dict(data)
    new_data = _dict_to_structured_helper(data, dtype=data_dtype)
    return new_data

unstructured_to_structured(data, dtype)

Source code in oqd-dataschema/src/oqd_dataschema/utils.py
def unstructured_to_structured(data, dtype):
    data = list(np.moveaxis(data, -1, 0))

    leaves = len(rfn.flatten_descr(dtype))
    if len(data) != leaves:
        raise ValueError(
            f"Incompatible shape, last dimension of data ({data.shape[-1]}) must match number of leaves in structured dtype ({leaves})."
        )

    new_data = _unstructured_to_structured_helper(data, dtype)

    return new_data