Skip to content

Commit 316a966

Browse files
committed
TST: add test for new numpy memmap behavior
memmap behavior is about to change with merge of numpy/numpy#7406. Test for behavior change so we can adapt expected mmap return values on an image.
1 parent b3a63a6 commit 316a966

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

nibabel/testing/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
data_path = abspath(pjoin(dirname(__file__), '..', 'tests', 'data'))
3030

3131

32+
from .np_features import VIRAL_MEMMAP
33+
3234
def assert_dt_equal(a, b):
3335
""" Assert two numpy dtype specifiers are equal
3436

nibabel/testing/np_features.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
""" Look for changes in numpy behavior over versions
2+
"""
3+
4+
import numpy as np
5+
6+
7+
def _memmap_after_ufunc():
8+
""" Return True if memmap arrays always return memmap from ufuncs
9+
10+
This should be True for numpy < 1.12, False otherwise.
11+
"""
12+
with open(__file__, 'rb') as fobj:
13+
mm_arr = np.memmap(fobj, mode='r', shape=(10,), dtype=np.uint8)
14+
mm_preserved = isinstance(mm_arr + 1, np.memmap)
15+
return mm_preserved
16+
17+
18+
# True if ufunc on memmap retuns a memmap
19+
VIRAL_MEMMAP = _memmap_after_ufunc()

0 commit comments

Comments
 (0)