From: W. Trevor King Date: Wed, 12 Sep 2012 20:52:22 +0000 (-0400) Subject: storage:hdf5: convert int/float lists to builtin Python types on load. X-Git-Tag: v0.3~3 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=263932989d12a9e3e98c056a6b67c27d33957be8;p=h5config.git storage:hdf5: convert int/float lists to builtin Python types on load. This avoids loading a FloatListSetting as a list of `numpy.float64`s, which lead to problems if you attempted to serialize the resulting config using `YAML_Storage`: Traceback (most recent call last): ... File ".../h5config/storage/yaml.py", line 140, in _save default_flow_style=False) File "/usr/lib64/python2.7/site-packages/yaml/__init__.py", line 202, in dump return dump_all([data], stream, Dumper=Dumper, **kwds) ... File "/usr/lib64/python2.7/site-packages/yaml/representer.py", line 247, in represent_undefined raise RepresenterError("cannot represent an object: %s" % data) yaml.representer.RepresenterError: cannot represent an object: 0.0 --- diff --git a/h5config/storage/hdf5.py b/h5config/storage/hdf5.py index 6b8a0bc..ce81289 100644 --- a/h5config/storage/hdf5.py +++ b/h5config/storage/hdf5.py @@ -233,7 +233,12 @@ class HDF5_Storage (_FileStorage): elif isinstance(s, _config.NumericSetting): raise NotImplementedError(type(s)) elif isinstance(s, _config.ListSetting): - v = list(v) # convert from numpy array + # convert from numpy array + if isinstance(s, _config.IntegerListSetting): + conv = int + elif isinstance(s, _config.FloatListSetting): + conv = float + v = list(conv(x) for x in v) if _is_string(v): # convert back from None, etc. v = s.convert_from_text(v)