From: W. Trevor King Date: Tue, 27 Sep 2011 18:41:24 +0000 (-0400) Subject: Rework de-numpy-ing in hdf5 module (now also de-numpy floats and ints). X-Git-Tag: v0.2~18 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=3cb08ded01490dc5280a526461ccff8e0305f0f5;p=h5config.git Rework de-numpy-ing in hdf5 module (now also de-numpy floats and ints). --- diff --git a/h5config/storage/hdf5.py b/h5config/storage/hdf5.py index c2add45..f0a214f 100644 --- a/h5config/storage/hdf5.py +++ b/h5config/storage/hdf5.py @@ -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)