[python-hdf5storage] 06/12: Fixed bug where MATLAB structures could not be read back correctly in Python 2.
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:24:49 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 946f5137647df16d56a938e17bdc4da1bb661ae0
Author: Freja Nordsiek <fnordsie at gmail.com>
Date: Fri Mar 7 18:28:25 2014 -0500
Fixed bug where MATLAB structures could not be read back correctly in Python 2.
---
hdf5storage/Marshallers.py | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/hdf5storage/Marshallers.py b/hdf5storage/Marshallers.py
index 2c94ca3..0fc408d 100644
--- a/hdf5storage/Marshallers.py
+++ b/hdf5storage/Marshallers.py
@@ -968,6 +968,15 @@ class NumpyScalarArrayMarshaller(TypeMarshaller):
dt_whole = []
for k in fields:
+ # In Python 2, the field names for a structured ndarray
+ # must be ascii (str) as opposed to unicode, so k needs
+ # to be converted in the Python 2 case.
+ if sys.hexversion >= 0x03000000:
+ k_name = k
+ else:
+ k_name = k.encode()
+
+ # Read the value.
v = struct_data[k]
# If any of the elements are not Numpy types or if they
@@ -975,7 +984,7 @@ class NumpyScalarArrayMarshaller(TypeMarshaller):
# this field will just be an object field.
if v.size == 0 or not isinstance(v.flatten()[0], \
tuple(self.types)):
- dt_whole.append((k, 'object'))
+ dt_whole.append((k_name, 'object'))
continue
first = v.flatten()[0]
@@ -991,9 +1000,9 @@ class NumpyScalarArrayMarshaller(TypeMarshaller):
# If they are all the same, then dt and shape should be
# used. Otherwise, it has to be object.
if all_same:
- dt_whole.append((k, dt, sp))
+ dt_whole.append((k_name, dt, sp))
else:
- dt_whole.append((k, 'object'))
+ dt_whole.append((k_name, 'object'))
# Make the structured ndarray with the constructed
# dtype. The shape is simply the shape of the object arrays
--
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