[python-hdf5storage] 29/152: Fixed reading bugs.

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:24:31 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 1a72e516428f309034a7724064aa832055f11ee7
Author: Freja Nordsiek <fnordsie at gmail.com>
Date:   Sat Jan 25 18:22:15 2014 -0500

    Fixed reading bugs.
---
 hdf5storage/Marshallers.py | 17 ++++++++++-------
 hdf5storage/utilities.py   |  2 +-
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/hdf5storage/Marshallers.py b/hdf5storage/Marshallers.py
index b2dbece..7c812bb 100644
--- a/hdf5storage/Marshallers.py
+++ b/hdf5storage/Marshallers.py
@@ -537,7 +537,7 @@ class NumpyScalarArrayMarshaller(TypeMarshaller):
             # needs to be reshaped.
             if tuple(shape) != data.shape \
                     and np.prod(shape) == np.prod(data.shape):
-                data.shape = tuple(shape)
+                data = data.reshape(tuple(shape))
 
             # String types might have to be decoded depending on the
             # underlying type, and MATLAB class if given.
@@ -612,13 +612,16 @@ class PythonScalarMarshaller(NumpyScalarArrayMarshaller):
                                                options)
 
         # The type string determines how to convert it back to a Python
-        # type (just look up the entry in types). Otherwise, return it
-        # as is.
+        # type (just look up the entry in types). As it might be
+        # returned as an ndarray, it needs to be run through
+        # np.asscalar.
         type_string = get_attribute_string(grp[name], 'CPython.Type')
         if type_string in self.cpython_type_strings:
-            return self.types[self.cpython_type_strings.find( \
-                type_string)](data)
+            tp = self.types[self.cpython_type_strings.index(
+                            type_string)]
+            return tp(np.asscalar(data))
         else:
+            # Must be some other type, so return it as is.
             return data
 
 
@@ -654,7 +657,7 @@ class PythonStringMarshaller(NumpyScalarArrayMarshaller):
         # as is.
         type_string = get_attribute_string(grp[name], 'CPython.Type')
         if type_string == 'str':
-            return data.decode()
+            return data.tostring().decode()
         elif type_string == 'bytes':
             return data.tostring()
         elif type_string == 'bytearray':
@@ -735,7 +738,7 @@ class PythonDictMarshaller(TypeMarshaller):
         # doing MATLAB compatibility (otherwise, the attribute needs to
         # be deleted).
         for k, v in data.items():
-            write_data(f, grp2, k, v, None, Options)
+            write_data(f, grp2, k, v, None, options)
             if options.MATLAB_compatible:
                 set_attribute_string(grp2[k], 'H5PATH', grp2.name)
             else:
diff --git a/hdf5storage/utilities.py b/hdf5storage/utilities.py
index d9ba425..25cf147 100644
--- a/hdf5storage/utilities.py
+++ b/hdf5storage/utilities.py
@@ -150,7 +150,7 @@ def decode_to_numpy_ascii(data):
 
     """
     # Convert first to a Python str if it isn't already an np.string_.
-    if not isinstance(data, np.string) \
+    if not isinstance(data, np.string_) \
             and not (isinstance(data, np.ndarray) \
             and data.dtype.name.startswith('bytes')):
         data = decode_to_str(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