[h5py] 423/455: Fix TypeError with field names on non-compound datasets

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:57 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 83e63be2d58a0c93dedc7a442678fd96f5c750b6
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Sun Feb 21 22:50:12 2010 +0000

    Fix TypeError with field names on non-compound datasets
---
 h5py/highlevel.py               | 2 ++
 h5py/tests/high/test_dataset.py | 5 +++++
 2 files changed, 7 insertions(+)

diff --git a/h5py/highlevel.py b/h5py/highlevel.py
index d8f529c..833029a 100644
--- a/h5py/highlevel.py
+++ b/h5py/highlevel.py
@@ -1188,6 +1188,8 @@ class Dataset(HLObject):
             basetype = self.id.dtype
             if len(names) == 0:
                 new_dtype = basetype
+            elif basetype.names is None:
+                raise ValueError("Field names only allowed for compound types")
             else:
                 for name in names:
                     if not name in basetype.names:
diff --git a/h5py/tests/high/test_dataset.py b/h5py/tests/high/test_dataset.py
index 94882b9..2d8e734 100644
--- a/h5py/tests/high/test_dataset.py
+++ b/h5py/tests/high/test_dataset.py
@@ -40,4 +40,9 @@ class TestArray(Base):
         self.assertEqual(arr.dtype, np.dtype('i1'))
         self.assertArrayEqual(arr, data.astype(arr.dtype))
 
+    def test_fieldname_exc(self):
+        """ (Dataset) Field name on non-compound dataset raises ValueError """
+        ds = self.f.create_dataset('foo', (100,), 'f')
+        self.assertRaises(ValueError, ds.__getitem__, (0, 'a'))
+
         

-- 
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