[h5py] 403/455: Fix KeyError for weird float sizes

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:55 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 5a01717bc380cbc011975ff8b07ed8e558d1590a
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Wed Feb 10 06:34:06 2010 +0000

    Fix KeyError for weird float sizes
---
 h5py/h5t.pyx               | 52 ++++++++++++++++++++++++++--------------------
 h5py/tests/low/test_h5t.py |  7 +++++++
 2 files changed, 36 insertions(+), 23 deletions(-)

diff --git a/h5py/h5t.pyx b/h5py/h5t.pyx
index 9174317..f3902c9 100644
--- a/h5py/h5t.pyx
+++ b/h5py/h5t.pyx
@@ -1172,36 +1172,42 @@ cdef dict _uint_nt = {1: H5T_NATIVE_UINT8, 2: H5T_NATIVE_UINT16, 4: H5T_NATIVE_U
 cdef TypeFloatID _c_float(dtype dt):
     # Floats (single and double)
     cdef hid_t tid
-
-    if dt.byteorder == c'<':
-        tid =  _float_le[dt.elsize]
-    elif dt.byteorder == c'>':
-        tid =  _float_be[dt.elsize]
-    else:
-        tid =  _float_nt[dt.elsize]
+
+    try:
+        if dt.byteorder == c'<':
+            tid =  _float_le[dt.elsize]
+        elif dt.byteorder == c'>':
+            tid =  _float_be[dt.elsize]
+        else:
+            tid =  _float_nt[dt.elsize]
+    except KeyError:
+        raise TypeError("Unsupported float size (%s)" % dt.elsize)
 
     return TypeFloatID(H5Tcopy(tid))
 
 cdef TypeIntegerID _c_int(dtype dt):
     # Integers (ints and uints)
     cdef hid_t tid
-
-    if dt.kind == c'i':
-        if dt.byteorder == c'<':
-            tid = _int_le[dt.elsize]
-        elif dt.byteorder == c'>':
-            tid = _int_be[dt.elsize]
-        else:
-            tid = _int_nt[dt.elsize]
-    elif dt.kind == c'u':
-        if dt.byteorder == c'<':
-            tid = _uint_le[dt.elsize]
-        elif dt.byteorder == c'>':
-            tid = _uint_be[dt.elsize]
+
+    try:
+        if dt.kind == c'i':
+            if dt.byteorder == c'<':
+                tid = _int_le[dt.elsize]
+            elif dt.byteorder == c'>':
+                tid = _int_be[dt.elsize]
+            else:
+                tid = _int_nt[dt.elsize]
+        elif dt.kind == c'u':
+            if dt.byteorder == c'<':
+                tid = _uint_le[dt.elsize]
+            elif dt.byteorder == c'>':
+                tid = _uint_be[dt.elsize]
+            else:
+                tid = _uint_nt[dt.elsize]
         else:
-            tid = _uint_nt[dt.elsize]
-    else:
-        raise TypeError('Illegal int kind "%s"' % dt.kind)
+            raise TypeError('Illegal int kind "%s"' % dt.kind)
+    except KeyError:
+        raise TypeError("Unsupported integer size (%s)" % dt.elsize)
 
     return TypeIntegerID(H5Tcopy(tid))
 
diff --git a/h5py/tests/low/test_h5t.py b/h5py/tests/low/test_h5t.py
index 52c84d8..3c49fcd 100644
--- a/h5py/tests/low/test_h5t.py
+++ b/h5py/tests/low/test_h5t.py
@@ -85,6 +85,13 @@ class TestTypeID(Base):
         """ (H5T) get_class() """
         self.assertEqual(h5t.STD_I32LE.get_class(), h5t.INTEGER)
 
+class TestFloat(Base):
+
+    def test_float_exc(self):
+        """ (H5T) Unsupported float size raises TypeError """
+        import numpy
+        if hasattr(numpy, 'float128'):
+            self.assertRaises(TypeError, h5t.py_create, numpy.float128)
 
     
 

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