@@ -266,12 +266,21 @@ def getTypeItem(dt):
266
266
267
267
elif dt .kind == 'b' :
268
268
# boolean type - h5py stores as enum
269
- if dt .base == dt :
270
- raise TypeError ("Expected base type to be different than parent" )
271
- baseType = getBaseType (dt )
269
+ # assume LE unless the numpy byteorder is '>'
270
+ byteorder = 'LE'
271
+ if dt .base .byteorder == '>' :
272
+ byteorder = 'BE'
273
+ # this mapping is an h5py convention for boolean support
274
+ mapping = {
275
+ "FALSE" : 0 ,
276
+ "TRUE" : 1
277
+ }
272
278
type_info ['class' ] = 'H5T_ENUM'
273
- type_info ['mapping' ] = {"false" : 0 , "true" : 1 }
274
- type_info ['base' ] = getTypeItem (dt .base )
279
+ type_info ['mapping' ] = mapping
280
+ base_info = { "class" : "H5T_INTEGER" }
281
+ base_info ['base' ] = "H5T_STD_I8" + byteorder
282
+ type_info ["base" ] = base_info
283
+
275
284
elif dt .kind == 'f' :
276
285
# floating point type
277
286
type_info ['class' ] = 'H5T_FLOAT'
@@ -525,6 +534,22 @@ def createDataType(typeItem):
525
534
subtypes .append ((field ['name' ], dt )) # append tuple
526
535
527
536
dtRet = np .dtype (subtypes )
537
+ elif typeClass == 'H5T_ENUM' :
538
+ if 'base' not in typeItem :
539
+ raise KeyError ("Expected 'base' to be provided for enum type" )
540
+ base_json = typeItem ["base" ]
541
+ if 'class' not in base_json :
542
+ raise KeyError ("Expected class field in base type" )
543
+ if base_json ['class' ] != 'H5T_INTEGER' :
544
+ raise TypeError ("Only integer base types can be used with enum type" )
545
+ if 'mapping' not in typeItem :
546
+ raise KeyError ("'mapping' not provided for enum type" )
547
+ mapping = typeItem ["mapping" ]
548
+ if len (mapping ) == 0 :
549
+ raise KeyError ("empty enum map" )
550
+ dt = createBaseDataType (base_json )
551
+ dtRet = special_dtype (enum = (dt , mapping ))
552
+
528
553
else :
529
554
dtRet = createBaseDataType (typeItem ) # create non-compound dt
530
555
return dtRet
0 commit comments