Skip to content

Commit 9d24a5d

Browse files
committed
Merge remote-tracking branch 'upstream/maint/2.5.x' into fix/gifti_types
2 parents cf259b2 + 457c860 commit 9d24a5d

10 files changed

+70
-18
lines changed

appveyor.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22
# CI on Windows via appveyor
33

44
environment:
5+
DEPENDS: numpy scipy matplotlib h5py pydicom
56

67
matrix:
78
- PYTHON: C:\Python27
89
- PYTHON: C:\Python27-x64
910
- PYTHON: C:\Python34
11+
DEPENDS: --prefer-binary numpy scipy matplotlib h5py pydicom
1012
- PYTHON: C:\Python34-x64
13+
DEPENDS: --prefer-binary numpy scipy matplotlib h5py pydicom
1114
- PYTHON: C:\Python35
1215
- PYTHON: C:\Python35-x64
16+
- PYTHON: C:\Python35-x64
17+
PYTHONHASHSEED: 283137131
18+
DEPENDS: "h5py==2.9.0"
1319
- PYTHON: C:\Python36
1420
- PYTHON: C:\Python36-x64
1521
- PYTHON: C:\Python37
@@ -28,7 +34,7 @@ install:
2834

2935
# Install the dependencies of the project.
3036
- pip install --upgrade pip setuptools>=27.0 wheel
31-
- pip install numpy scipy matplotlib h5py pydicom
37+
- pip install %DEPENDS%
3238
- pip install nose mock coverage codecov
3339
- pip install .
3440
- SET NIBABEL_DATA_DIR=%CD%\nibabel-data

nibabel/_h5py_compat.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import sys
2+
import os
3+
from .optpkg import optional_package
4+
5+
# PY35: A bug affected Windows installations of h5py in Python3 versions <3.6
6+
# due to random dictionary ordering, causing float64 data arrays to sometimes be
7+
# loaded as longdouble (also 64 bit on Windows). This caused stochastic failures
8+
# to correctly handle data caches, and possibly other subtle bugs we never
9+
# caught. This was fixed in h5py 2.10.
10+
# Please see https://github.com/nipy/nibabel/issues/665 for details.
11+
min_h5py = '2.10' if os.name == 'nt' and (3,) <= sys.version_info < (3, 6) else None
12+
h5py, have_h5py, setup_module = optional_package('h5py', min_version=min_h5py)

nibabel/minc1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def _normalize(self, data, sliceobj=()):
173173
applied to `data`
174174
"""
175175
ddt = self.get_data_dtype()
176-
if ddt.type in np.sctypes['float']:
176+
if np.issubdtype(ddt.type, np.floating):
177177
return data
178178
image_max = self._image_max
179179
image_min = self._image_min

nibabel/minc2.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
import numpy as np
2929

3030
from .keywordonly import kw_only_meth
31-
from .optpkg import optional_package
32-
h5py, have_h5py, setup_module = optional_package('h5py')
31+
from ._h5py_compat import h5py
3332

3433
from .minc1 import Minc1File, MincHeader, Minc1Image, MincError
3534

nibabel/tests/test_h5py_compat.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""
2+
These tests are almost certainly overkill, but serve to verify that
3+
the behavior of _h5py_compat is pass-through in all but a small set of
4+
well-defined cases
5+
"""
6+
import sys
7+
import os
8+
from distutils.version import LooseVersion
9+
import numpy as np
10+
11+
from ..optpkg import optional_package
12+
from .. import _h5py_compat as compat
13+
from ..testing import assert_equal, assert_true, assert_false, assert_not_equal
14+
15+
h5py, have_h5py, _ = optional_package('h5py')
16+
17+
18+
def test_optpkg_equivalence():
19+
# No effect on Linux/OSX
20+
if os.name == 'posix':
21+
assert_equal(have_h5py, compat.have_h5py)
22+
# No effect on Python 2.7 or 3.6+
23+
if sys.version_info >= (3, 6) or sys.version_info < (3,):
24+
assert_equal(have_h5py, compat.have_h5py)
25+
# Available in a strict subset of cases
26+
if not have_h5py:
27+
assert_false(compat.have_h5py)
28+
# Available when version is high enough
29+
elif LooseVersion(h5py.__version__) >= '2.10':
30+
assert_true(compat.have_h5py)
31+
32+
33+
def test_disabled_h5py_cases():
34+
# On mismatch
35+
if have_h5py and not compat.have_h5py:
36+
# Recapitulate min_h5py conditions from _h5py_compat
37+
assert_equal(os.name, 'nt')
38+
assert_true((3,) <= sys.version_info < (3, 6))
39+
assert_true(LooseVersion(h5py.__version__) < '2.10')
40+
# Verify that the root cause is present
41+
# If any tests fail, they will likely be these, so they may be
42+
# ill-advised...
43+
assert_equal(str(np.longdouble), str(np.float64))
44+
assert_not_equal(np.longdouble, np.float64)

nibabel/tests/test_image_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
from ..optpkg import optional_package
3636
_, have_scipy, _ = optional_package('scipy')
37-
_, have_h5py, _ = optional_package('h5py')
37+
from .._h5py_compat import have_h5py
3838

3939
from .. import (AnalyzeImage, Spm99AnalyzeImage, Spm2AnalyzeImage,
4040
Nifti1Pair, Nifti1Image, Nifti2Pair, Nifti2Image,

nibabel/tests/test_imageclasses.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66

77
import numpy as np
88

9-
from nibabel.optpkg import optional_package
10-
119
import nibabel as nib
1210
from nibabel.analyze import AnalyzeImage
1311
from nibabel.nifti1 import Nifti1Image
1412
from nibabel.nifti2 import Nifti2Image
13+
from .._h5py_compat import have_h5py
1514

1615
from nibabel import imageclasses
1716
from nibabel.imageclasses import spatial_axes_first, class_map, ext_map
@@ -23,8 +22,6 @@
2322

2423
DATA_DIR = pjoin(dirname(__file__), 'data')
2524

26-
have_h5py = optional_package('h5py')[1]
27-
2825
MINC_3DS = ('minc1_1_scale.mnc',)
2926
MINC_4DS = ('minc1_4d.mnc',)
3027
if have_h5py:

nibabel/tests/test_minc2.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@
1212

1313
import numpy as np
1414

15-
from ..optpkg import optional_package
16-
17-
h5py, have_h5py, setup_module = optional_package('h5py')
18-
1915
from .. import minc2
2016
from ..minc2 import Minc2File, Minc2Image
17+
from .._h5py_compat import h5py, have_h5py, setup_module
2118

2219
from nose.tools import (assert_true, assert_equal, assert_false, assert_raises)
2320

nibabel/tests/test_minc2_data.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515

1616
import numpy as np
1717

18-
from nibabel.optpkg import optional_package
19-
20-
h5py, have_h5py, setup_module = optional_package('h5py')
18+
from .._h5py_compat import h5py, have_h5py, setup_module
2119

2220
from .nibabel_data import get_nibabel_data, needs_nibabel_data
2321
from .. import load as top_load, Nifti1Image

nibabel/tests/test_proxy_api.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@
4646
from .. import minc1
4747
from ..externals.netcdf import netcdf_file
4848
from .. import minc2
49-
from ..optpkg import optional_package
50-
h5py, have_h5py, _ = optional_package('h5py')
49+
from .._h5py_compat import h5py, have_h5py
5150
from .. import ecat
5251
from .. import parrec
5352

0 commit comments

Comments
 (0)