[h5py] 440/455: Fix TypeError with oddly-formed array dtypes
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:59 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to annotated tag 1.3.0
in repository h5py.
commit 804c1452081c45ec672c55f40485f412c6d51d1e
Author: andrewcollette <andrew.collette at gmail.com>
Date: Thu Mar 4 03:33:35 2010 +0000
Fix TypeError with oddly-formed array dtypes
---
h5py/h5t.pyx | 11 +++++++++--
h5py/tests/high/test_dataset.py | 17 +++++++++++++++++
2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/h5py/h5t.pyx b/h5py/h5t.pyx
index f3902c9..bd436ed 100644
--- a/h5py/h5t.pyx
+++ b/h5py/h5t.pyx
@@ -1239,9 +1239,16 @@ cdef TypeArrayID _c_array(dtype dt, int logical):
# Arrays
cdef dtype base
cdef TypeID type_base
- cdef tuple shape
+ cdef object shape
- base, shape = dt.subdtype
+ base, shape = dt.subdtype
+ try:
+ shape = tuple(shape)
+ except TypeError:
+ try:
+ shape = (int(shape),)
+ except TypeError:
+ raise TypeError("Array shape for dtype must be a sequence or integer")
type_base = py_create(base, logical=logical)
return array_create(type_base, shape)
diff --git a/h5py/tests/high/test_dataset.py b/h5py/tests/high/test_dataset.py
index 2d8e734..fa5cee7 100644
--- a/h5py/tests/high/test_dataset.py
+++ b/h5py/tests/high/test_dataset.py
@@ -16,6 +16,23 @@ class Base(tests.HTest):
self.f.close()
os.unlink(self.name)
+class TestTypes(Base):
+
+ def test_array_dtype(self):
+ """ (Dataset) Array dtypes using non-tuple shapes """
+ dt1 = np.dtype('f4', (2,))
+ dt2 = np.dtype('f4', [2])
+ dt3 = np.dtype('f4', 2)
+ dt4 = np.dtype('f4', 2.1)
+ ds1 = self.f.create_dataset('ds1', (1,), dt1)
+ ds2 = self.f.create_dataset('ds2', (1,), dt2)
+ ds3 = self.f.create_dataset('ds3', (1,), dt3)
+ ds4 = self.f.create_dataset('ds4', (1,), dt4)
+ self.assertEqual(ds1.dtype, dt1)
+ self.assertEqual(ds2.dtype, dt1)
+ self.assertEqual(ds3.dtype, dt1)
+ self.assertEqual(ds4.dtype, dt1)
+
class TestArray(Base):
def test_array(self):
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/h5py.git
More information about the debian-science-commits
mailing list