[python-hdf5storage] 01/12: Fixed bug where str was converted to numpy.bytes_ instead of numpy.str_ before writing.

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:24:48 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to annotated tag 0.1.1
in repository python-hdf5storage.

commit c62b3c330668299de1387b4a23e13c2a148c2b77
Author: Freja Nordsiek <fnordsie at gmail.com>
Date:   Fri Mar 7 16:26:02 2014 -0500

    Fixed bug where str was converted to numpy.bytes_ instead of numpy.str_ before writing.
---
 hdf5storage/Marshallers.py | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/hdf5storage/Marshallers.py b/hdf5storage/Marshallers.py
index dc531c5..2c94ca3 100644
--- a/hdf5storage/Marshallers.py
+++ b/hdf5storage/Marshallers.py
@@ -1211,8 +1211,14 @@ class PythonStringMarshaller(NumpyScalarArrayMarshaller):
         self.matlab_classes = []
 
     def write(self, f, grp, name, data, type_string, options):
-        # data just needs to be converted to a numpy string.
-        cdata = np.bytes_(data)
+        # data just needs to be converted to a numpy string of the
+        # appropriate type (str to np.str_ and the others to np.bytes_).
+        if (sys.hexversion >= 0x03000000 and isinstance(data, str)) \
+                or (sys.hexversion < 0x03000000 \
+                and isinstance(data, unicode)):
+            cdata = np.unicode_(data)
+        else:
+            cdata = np.bytes_(data)
 
         # Now pass it to the parent version of this function to write
         # it. The proper type_string needs to be grabbed now as the
@@ -1233,10 +1239,7 @@ class PythonStringMarshaller(NumpyScalarArrayMarshaller):
         # as is.
         type_string = get_attribute_string(grp[name], 'Python.Type')
         if type_string == 'str':
-            if isinstance(data, np.ndarray):
-                return data.tostring().decode()
-            else:
-                return data.decode()
+            return convert_to_str(data)
         elif type_string == 'bytes':
             if sys.hexversion >= 0x03000000:
                 return bytes(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