[python-hdf5storage] 79/84: Fixed bug where a structured ndarray with a field having the name 'O' was always written as an HDF5 Group.
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:25:06 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to annotated tag 0.1.10
in repository python-hdf5storage.
commit 987c893457258316c3beb22d81ad2b7a22089735
Author: Freja Nordsiek <fnordsie at gmail.com>
Date: Mon Sep 7 20:09:35 2015 -0400
Fixed bug where a structured ndarray with a field having the name 'O' was always written as an HDF5 Group.
---
README.rst | 8 +++-
hdf5storage/Marshallers.py | 6 +--
tests/test_ndarray_O_field.py | 98 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 108 insertions(+), 4 deletions(-)
diff --git a/README.rst b/README.rst
index 8681015..ebf765d 100644
--- a/README.rst
+++ b/README.rst
@@ -213,7 +213,13 @@ canonical empty 0.1 ``np.float64([])``
Versions
========
-0.1.9. Minor feature release adding optional data compression and the storage of data checksums. Controlled by several new options.
+0.1.9. Bugfix and minor feature release doing the following.
+ * Issue #23. Fixed bug where a structured ``np.ndarray`` with
+ a field name of ``'O'`` could never be written as an
+ HDF5 COMPOUND Dataset (falsely thought a field's dtype was
+ object).
+ * Issue #6. Added optional data compression and the storage of
+ data checksums. Controlled by several new options.
0.1.8. Bugfix release fixing the following two bugs.
* Issue #21. Fixed bug where the ``'MATLAB_class'`` Attribute is
diff --git a/hdf5storage/Marshallers.py b/hdf5storage/Marshallers.py
index b64ec14..55541f0 100644
--- a/hdf5storage/Marshallers.py
+++ b/hdf5storage/Marshallers.py
@@ -678,15 +678,15 @@ class NumpyScalarArrayMarshaller(TypeMarshaller):
# those have to be excluded too. Also, if any of its fields are
# an object time (no matter how nested), then rather than
# converting that field to a HDF5 Reference types, it will just
- # be written as a Group instead (just have to see if "'O'" is in
- # str(data_to_store.dtype).
+ # be written as a Group instead (just have to see if ", 'O'" is
+ # in str(data_to_store.dtype).
if data_to_store.dtype.fields is not None \
and h5py.check_dtype(ref=data_to_store.dtype) \
is not h5py.Reference \
and not np.iscomplexobj(data) \
and (options.structured_numpy_ndarray_as_struct \
- or "'O'" in str(data_to_store.dtype) \
+ or ", 'O'" in str(data_to_store.dtype) \
or not all(data_to_store.shape) \
or not all([all(data_to_store[n].shape) \
for n in data_to_store.dtype.names])):
diff --git a/tests/test_ndarray_O_field.py b/tests/test_ndarray_O_field.py
new file mode 100644
index 0000000..f4af940
--- /dev/null
+++ b/tests/test_ndarray_O_field.py
@@ -0,0 +1,98 @@
+# Copyright (c) 2013-2015, Freja Nordsiek
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import os
+import os.path
+
+import numpy as np
+import h5py
+
+import hdf5storage
+
+
+filename = 'data.mat'
+
+
+# A series of tests to make sure that structured ndarrays with a field
+# that has an object dtype are written like structs (are HDF5 Groups)
+# but are written as an HDF5 COMPOUND Dataset otherwise (even in the
+# case that a field's name is 'O').
+
+
+def test_O_field_compound():
+ name = '/a'
+ data = np.empty(shape=(1, ), dtype=[('O', 'int8'), ('a', 'uint16')])
+ if os.path.exists(filename):
+ os.remove(filename)
+ try:
+ hdf5storage.write(data, path=name, filename=filename,
+ matlab_compatible=False,
+ structured_numpy_ndarray_as_struct=False)
+ with h5py.File(filename) as f:
+ assert isinstance(f[name], h5py.Dataset)
+ except:
+ raise
+ finally:
+ if os.path.exists(filename):
+ os.remove(filename)
+
+
+def test_object_field_group():
+ name = '/a'
+ data = np.empty(shape=(1, ), dtype=[('a', 'O'), ('b', 'uint16')])
+ data['a'][0] = [1, 2]
+ if os.path.exists(filename):
+ os.remove(filename)
+ try:
+ hdf5storage.write(data, path=name, filename=filename,
+ matlab_compatible=False,
+ structured_numpy_ndarray_as_struct=False)
+ with h5py.File(filename) as f:
+ assert isinstance(f[name], h5py.Group)
+ except:
+ raise
+ finally:
+ if os.path.exists(filename):
+ os.remove(filename)
+
+
+def test_O_and_object_field_group():
+ name = '/a'
+ data = np.empty(shape=(1, ), dtype=[('a', 'O'), ('O', 'uint16')])
+ data['a'][0] = [1, 2]
+ if os.path.exists(filename):
+ os.remove(filename)
+ try:
+ hdf5storage.write(data, path=name, filename=filename,
+ matlab_compatible=False,
+ structured_numpy_ndarray_as_struct=False)
+ with h5py.File(filename) as f:
+ assert isinstance(f[name], h5py.Group)
+ except:
+ raise
+ finally:
+ if os.path.exists(filename):
+ os.remove(filename)
--
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