Rework de-numpy-ing in hdf5 module (now also de-numpy floats and ints).
authorW. Trevor King <wking@drexel.edu>
Tue, 27 Sep 2011 18:41:24 +0000 (14:41 -0400)
committerW. Trevor King <wking@drexel.edu>
Tue, 27 Sep 2011 18:41:24 +0000 (14:41 -0400)
h5config/storage/hdf5.py

index c2add451eed5c0a57e421bacf1ebba7a78b901c4..f0a214fb4d558f6a92e475f773de3801bd5579e8 100644 (file)
@@ -184,14 +184,19 @@ class HDF5_Storage (_FileStorage):
                         self._load(config=config[s.name], group=cwg)
                 else:
                     v = group[s.name][...]
-                    if isinstance(s, _config.BooleanSetting):
-                        if isinstance(v, _numpy.ndarray):
+                    if isinstance(v, _numpy.ndarray):
+                        if isinstance(s, _config.BooleanSetting):
                             v = bool(v)  # array(True, dtype=bool) -> True
-                    elif (isinstance(v, _numpy.ndarray) and
-                          v.dtype.type == _numpy.string_):
-                        v = str(v)  # array('abc', dtype='|S3') -> 'abc'
-                    elif isinstance(s, _config.FloatListSetting):
-                        v = list(v)  # convert from numpy array
+                        elif v.dtype.type == _numpy.string_:
+                            v = str(v)  # array('abc', dtype='|S3') -> 'abc'
+                        elif isinstance(s, _config.IntegerSetting):
+                            v = int(v)  # array(3, dtpe='int32') -> 3
+                        elif isinstance(s, _config.FloatSetting):
+                            v = float(v)  # array(1.2, dtype='float64') -> 1.2
+                        elif isinstance(s, _config.NumericSetting):
+                            raise NotImplementedError(type(s))
+                        elif isinstance(s, _config.FloatListSetting):
+                            v = list(v)  # convert from numpy array
                     if isinstance(v, _types.StringTypes):
                         # convert back from None, etc.
                         v = s.convert_from_text(v)