Skip to content

Commit

Permalink
keep backward compatibility for enum members key
Browse files Browse the repository at this point in the history
  • Loading branch information
jreadey committed Feb 9, 2025
1 parent 133e962 commit 856ee65
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion data/json/bool_attr.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"class": "H5T_INTEGER"
},
"class": "H5T_ENUM",
"mapping": [
"members": [
{
"name": "FALSE",
"value": 0
Expand Down
2 changes: 1 addition & 1 deletion data/json/bool_dset.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"class": "H5T_INTEGER"
},
"class": "H5T_ENUM",
"mapping": [
"members": [
{
"name": "FALSE",
"value": 0
Expand Down
2 changes: 1 addition & 1 deletion data/json/enum_attr.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"class": "H5T_INTEGER"
},
"class": "H5T_ENUM",
"mapping": [
"members": [
{
"name": "GAS",
"value": 2
Expand Down
2 changes: 1 addition & 1 deletion data/json/enum_dset.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"class": "H5T_INTEGER"
},
"class": "H5T_ENUM",
"mapping": [
"members": [
{
"name": "GAS",
"value": 2
Expand Down
2 changes: 1 addition & 1 deletion src/h5json/hdf5db.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ def getObjByPath(self, path):
def getObjectByUuid(self, col_type, obj_uuid):
# col_type should be either "datasets", "groups", or "datatypes"
if col_type not in ("datasets", "groups", "datatypes"):
msg = "Unexpectd error, invalid col_type: [" + col_type + "]"
msg = "Unexpected error, invalid col_type: [" + col_type + "]"
self.log.error(msg)
raise IOError(errno.EIO, msg)
if col_type == "groups" and obj_uuid == self.dbGrp.attrs["rootUUID"]:
Expand Down
8 changes: 6 additions & 2 deletions src/h5json/hdf5dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,9 +735,13 @@ def createBaseDataType(typeItem):
if base_json["class"] != "H5T_INTEGER":
msg = "Only integer base types can be used with enum type"
raise TypeError(msg)
if "mapping" not in typeItem:
if "mapping" in typeItem:
mapping = typeItem["mapping"]
elif "members" in typeItem:
mapping = typeItem["members"] # backward-compatibility for hdf5-json
else:
raise KeyError("'mapping' not provided for enum type")
mapping = typeItem["mapping"]

if len(mapping) == 0:
raise KeyError("empty enum map")

Expand Down

0 comments on commit 856ee65

Please sign in to comment.