···11+From 5009e062a6f7d4e074cab0fcb42a780ac2b1d7d4 Mon Sep 17 00:00:00 2001
22+From: James Tocknell <aragilar@gmail.com>
33+Date: Thu, 28 Dec 2017 20:55:55 +1100
44+Subject: [PATCH] FIX: Don't reorder compound types, breaks on numpy 1.14
55+66+---
77+ h5py/h5t.pyx | 25 +++++++------------------
88+ setup.py | 2 +-
99+ tox.ini | 4 ++--
1010+ 3 files changed, 10 insertions(+), 21 deletions(-)
1111+1212+diff --git a/h5py/h5t.pyx b/h5py/h5t.pyx
1313+index cc2344e1..7445e9eb 100644
1414+--- a/h5py/h5t.pyx
1515++++ b/h5py/h5t.pyx
1616+@@ -1136,12 +1136,6 @@ cdef class TypeCompoundID(TypeCompositeID):
1717+ else:
1818+ if sys.version[0] == '3':
1919+ field_names = [x.decode('utf8') for x in field_names]
2020+- if len(field_names) > 0:
2121+- collated_fields = zip(field_names, field_types, field_offsets)
2222+- ordered_fields = sorted(
2323+- collated_fields, key=operator.itemgetter(2))
2424+- field_names, field_types, field_offsets = \
2525+- map(list, zip(*ordered_fields))
2626+ typeobj = dtype({
2727+ 'names': field_names,
2828+ 'formats': field_types,
2929+@@ -1458,8 +1452,7 @@ cdef TypeCompoundID _c_compound(dtype dt, int logical, int aligned):
3030+ cdef dtype member_dt
3131+ cdef size_t member_offset = 0
3232+3333+- cdef dict offsets = {}
3434+- cdef list fields = []
3535++ cdef dict fields = {}
3636+3737+ # The challenge with correctly converting a numpy/h5py dtype to a HDF5 type
3838+ # which is composed of subtypes has three aspects we must consider
3939+@@ -1468,19 +1461,14 @@ cdef TypeCompoundID _c_compound(dtype dt, int logical, int aligned):
4040+ # 2. For correct round-tripping of aligned dtypes, we need to consider how
4141+ # much padding we need by looking at the field offsets
4242+ # 3. There is no requirement that the offsets be monotonically increasing
4343+- # (so we start by sorting the names as a function of increasing offset)
4444+ #
4545+ # The code below tries to cover these aspects
4646+4747+- # Get offsets for each compound member
4848+- for name, field in dt.fields.items():
4949+- offsets[name] = field[1]
5050+-
5151+ # Build list of names, offsets, and types, sorted by increasing offset
5252+ # (i.e. the position of the member in the struct)
5353+- for name in sorted(dt.names, key=offsets.__getitem__):
5454++ for name in sorted(dt.names, key=(lambda n: dt.fields[n][1])):
5555+ field = dt.fields[name]
5656+- name = name.encode('utf8') if isinstance(name, unicode) else name
5757++ h5_name = name.encode('utf8') if isinstance(name, unicode) else name
5858+5959+ # Get HDF5 data types and set the offset for each member
6060+ member_dt = field[0]
6161+@@ -1489,7 +1477,7 @@ cdef TypeCompoundID _c_compound(dtype dt, int logical, int aligned):
6262+ if aligned and (member_offset > field[1]
6363+ or member_dt.itemsize != member_type.get_size()):
6464+ raise TypeError("Enforced alignment not compatible with HDF5 type")
6565+- fields.append((name, member_offset, member_type))
6666++ fields[name] = (h5_name, member_offset, member_type)
6767+6868+ # Update member offset based on the HDF5 type size
6969+ member_offset += member_type.get_size()
7070+@@ -1500,8 +1488,9 @@ cdef TypeCompoundID _c_compound(dtype dt, int logical, int aligned):
7171+7272+ # Create compound with the necessary size, and insert its members
7373+ tid = H5Tcreate(H5T_COMPOUND, member_offset)
7474+- for (name, member_offset, member_type) in fields:
7575+- H5Tinsert(tid, name, member_offset, member_type.id)
7676++ for name in dt.names:
7777++ h5_name, member_offset, member_type = fields[name]
7878++ H5Tinsert(tid, h5_name, member_offset, member_type.id)
7979+8080+ return TypeCompoundID(tid)
8181+8282+diff --git a/setup.py b/setup.py
8383+index ec2a78a7..bbb086f6 100755
8484+--- a/setup.py
8585++++ b/setup.py
8686+@@ -32,7 +32,7 @@
8787+ # these are required to build h5py
8888+ # RUN_REQUIRES is included as setup.py test needs RUN_REQUIRES for testing
8989+ # RUN_REQUIRES can be removed when setup.py test is removed
9090+-SETUP_REQUIRES = RUN_REQUIRES + [NUMPY_DEP, 'Cython>=0.19', 'pkgconfig']
9191++SETUP_REQUIRES = RUN_REQUIRES + [NUMPY_DEP, 'Cython>=0.23', 'pkgconfig']
9292+9393+ # Needed to avoid trying to install numpy/cython on pythons which the latest
9494+ # versions don't support
···866866 # necessary when sources have been copied from other store
867867 # locations.
868868 if [ "${dontMakeSourcesWritable:-0}" != 1 ]; then
869869- chmod -R u+w "$sourceRoot"
869869+ chmod -R u+w -- "$sourceRoot"
870870 fi
871871872872 runHook postUnpack