|
15 | 15 |
|
16 | 16 | import pickle
|
17 | 17 | from io import BytesIO
|
| 18 | +from packaging.version import Version |
18 | 19 | from ..tmpdirs import InTemporaryDirectory
|
19 | 20 |
|
20 | 21 | import numpy as np
|
21 | 22 |
|
| 23 | +from .. import __version__ |
22 | 24 | from ..arrayproxy import (ArrayProxy, is_proxy, reshape_dataobj, get_obj_dtype)
|
23 | 25 | from ..openers import ImageOpener
|
24 | 26 | from ..nifti1 import Nifti1Header
|
| 27 | +from ..deprecator import ExpiredDeprecationError |
25 | 28 |
|
26 | 29 | from unittest import mock
|
27 | 30 |
|
@@ -57,6 +60,10 @@ def copy(self):
|
57 | 60 |
|
58 | 61 | class CArrayProxy(ArrayProxy):
|
59 | 62 | # C array memory layout
|
| 63 | + _default_order = 'C' |
| 64 | + |
| 65 | + |
| 66 | +class DeprecatedCArrayProxy(ArrayProxy): |
60 | 67 | order = 'C'
|
61 | 68 |
|
62 | 69 |
|
@@ -203,6 +210,38 @@ def test_order_override(order):
|
203 | 210 | assert_array_equal(arr[sliceobj], prox[sliceobj])
|
204 | 211 |
|
205 | 212 |
|
| 213 | +def test_deprecated_order_classvar(): |
| 214 | + shape = (15, 16, 17) |
| 215 | + arr = np.arange(np.prod(shape)).reshape(shape) |
| 216 | + fobj = BytesIO() |
| 217 | + fobj.write(arr.tobytes(order='C')) |
| 218 | + sliceobj = (None, slice(None), 1, -1) |
| 219 | + |
| 220 | + # We don't really care about the original order, just that the behavior |
| 221 | + # of the deprecated mode matches the new behavior |
| 222 | + fprox = ArrayProxy(fobj, (shape, arr.dtype), order='F') |
| 223 | + cprox = ArrayProxy(fobj, (shape, arr.dtype), order='C') |
| 224 | + |
| 225 | + # Start raising errors when we crank the dev version |
| 226 | + if Version(__version__) >= Version('7.0.0.dev0'): |
| 227 | + cm = pytest.raises(ExpiredDeprecationError) |
| 228 | + else: |
| 229 | + cm = pytest.deprecated_call() |
| 230 | + |
| 231 | + with cm: |
| 232 | + prox = DeprecatedCArrayProxy(fobj, (shape, arr.dtype)) |
| 233 | + assert prox.order == 'C' |
| 234 | + assert_array_equal(prox[sliceobj], cprox[sliceobj]) |
| 235 | + with cm: |
| 236 | + prox = DeprecatedCArrayProxy(fobj, (shape, arr.dtype), order='C') |
| 237 | + assert prox.order == 'C' |
| 238 | + assert_array_equal(prox[sliceobj], cprox[sliceobj]) |
| 239 | + with cm: |
| 240 | + prox = DeprecatedCArrayProxy(fobj, (shape, arr.dtype), order='F') |
| 241 | + assert prox.order == 'F' |
| 242 | + assert_array_equal(prox[sliceobj], fprox[sliceobj]) |
| 243 | + |
| 244 | + |
206 | 245 | def test_is_proxy():
|
207 | 246 | # Test is_proxy function
|
208 | 247 | hdr = FunkyHeader((2, 3, 4))
|
|
0 commit comments