From 3cb08ded01490dc5280a526461ccff8e0305f0f5 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 27 Sep 2011 14:41:24 -0400 Subject: [PATCH] Rework de-numpy-ing in hdf5 module (now also de-numpy floats and ints). --- h5config/storage/hdf5.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) 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) -- 2.26.2