Skip to content

Unable to retrieve user datatype (eg. H5T_ENUM, H5T_COMPOUND) #111

@kmuehlbauer

Description

@kmuehlbauer

Due to the nested architecture of the classes it seems it isn't possible atm to retrieve the user datatype of a certain dataset.

This is also pretty involved in h5py and h5pyd (on top the mapping for reference),h5type is the dataset-handle in question. To retrieve the datatype I suggest to add this to the _meta property like below (as it would be called in h5netcdf):

_h5type_mapping = {
    "H5T_INTEGER": 0,
    "H5T_FLOAT": 1,
    "H5T_STRING": 3,
    "H5T_COMPOUND": 6,
    "H5T_ENUM": 8,
    "H5T_VLEN": 9,
}

module = h5type.__module__
if module.startswith("h5py."):
    h5typeid = h5type.id.get_type().get_class()
elif module.startswith("h5pyd."):
    h5typeid = _h5type_mapping[h5type.id.type_json["class"]]
elif module.startswith("pyfive."):
    dtype = h5type.id._meta.datatype
    if isinstance(dtype, tuple):
        if dtype[0] == "COMPOUND":
            h5typeid = 6
        elif dtype[0] == "ENUMERATION":
            h5typeid = 8
        elif "VLEN" in dtype[0]:
            h5typeid = 9
    else:
        if dtype.kind == "f":
            h5typeid = 1
        elif h5type.dtype.kind in ( "i", "u"):
            h5typeid = 0
        elif h5type.dtype.kind in ("S", "U"):
            h5typeid = 3

Would that be something you would support? Or maybe I do not see a more easy approach?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions