[python-hdf5storage] 55/152: Added read/write support for lists.
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:24:34 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to annotated tag 0.1
in repository python-hdf5storage.
commit bc9c847addbda82af96a91babe56adb0ba4cb071
Author: Freja Nordsiek <fnordsie at gmail.com>
Date: Tue Jan 28 02:45:29 2014 -0500
Added read/write support for lists.
---
README.rst | 1 +
doc/source/hdf5storage.Marshallers.rst | 26 ++++++++++++++++++++++++++
hdf5storage/Marshallers.py | 32 ++++++++++++++++++++++++++++++++
3 files changed, 59 insertions(+)
diff --git a/README.rst b/README.rst
index 02238ae..79d1bcd 100644
--- a/README.rst
+++ b/README.rst
@@ -84,6 +84,7 @@ np.str\_ 0.1 np.uint32 uint32 0.1 [2]_
np.bytes\_ 0.1 char 0.1
np.object\_ 0.1 cell 0.1
dict 0.1 struct 0.1 [3]_
+list 0.1 np.object\_ cell 0.1
============= ======= ================== ======= ========
.. [1] Converted to ASCII, so characters outside of that set are lost.
diff --git a/doc/source/hdf5storage.Marshallers.rst b/doc/source/hdf5storage.Marshallers.rst
index b2329b1..b30f3c0 100644
--- a/doc/source/hdf5storage.Marshallers.rst
+++ b/doc/source/hdf5storage.Marshallers.rst
@@ -169,3 +169,29 @@ PythonDictMarshaller
.. autoinstanceattribute:: PythonDictMarshaller.matlab_classes
:annotation: = ['struct']
+
+PythonListMarshaller
+----------------------
+
+.. autoclass:: PythonListMarshaller
+ :members: read, write
+ :show-inheritance:
+
+ .. autoinstanceattribute:: PythonListMarshaller.cpython_attributes
+ :annotation: = {'CPython.Type', 'CPython.Shape', 'CPython.Empty',
+ 'CPython.numpy.UnderlyingType',
+ 'CPython.numpy.Container'}
+
+ .. autoinstanceattribute:: PythonListMarshaller.matlab_attributes
+ :annotation: = {'H5PATH', 'MATLAB_class', 'MATLAB_empty',
+ 'MATLAB_int_decode'}
+
+ .. autoinstanceattribute:: PythonListMarshaller.types
+ :annotation: = [list]
+
+ .. autoinstanceattribute:: PythonListMarshaller.cpython_type_strings
+ :annotation: = ['list']
+
+ .. autoinstanceattribute:: PythonListMarshaller.matlab_classes
+ :annotation: = []
+
diff --git a/hdf5storage/Marshallers.py b/hdf5storage/Marshallers.py
index 4b85289..04ea6ee 100644
--- a/hdf5storage/Marshallers.py
+++ b/hdf5storage/Marshallers.py
@@ -959,3 +959,35 @@ class PythonDictMarshaller(TypeMarshaller):
except:
pass
return data
+
+
+class PythonListMarshaller(NumpyScalarArrayMarshaller):
+ def __init__(self):
+ NumpyScalarArrayMarshaller.__init__(self)
+ self.types = [list]
+ self.cpython_type_strings = ['list']
+ # As the parent class already has MATLAB strings handled, there
+ # are no MATLAB classes that this marshaller should be used for.
+ self.matlab_classes = []
+
+ def write(self, f, grp, name, data, type_string, options):
+ # data just needs to be converted to the appropriate numpy type
+ # (pass it through np.object_ to get the and then pass it to the
+ # parent version of this function. The proper type_string needs
+ # to be grabbed now as the parent function will have a modified
+ # form of data to guess from if not given the right one
+ # explicitly.
+ NumpyScalarArrayMarshaller.write(self, f, grp, name,
+ np.object_(data),
+ self.get_type_string(data,
+ type_string), options)
+
+ def read(self, f, grp, name, options):
+ # Use the parent class version to read it and do most of the
+ # work.
+ data = NumpyScalarArrayMarshaller.read(self, f, grp, name,
+ options)
+
+ # Passing it through list does all the work of making it a list
+ # again.
+ return list(data)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-hdf5storage.git
More information about the debian-science-commits
mailing list