Skip to content

Commit 70502e4

Browse files
committed
TEST: Check behavior of get_obj_dtype
1 parent 0a69fe7 commit 70502e4

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

nibabel/tests/test_arrayproxy.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import numpy as np
2121

22-
from ..arrayproxy import (ArrayProxy, is_proxy, reshape_dataobj)
22+
from ..arrayproxy import (ArrayProxy, is_proxy, reshape_dataobj, get_obj_dtype)
2323
from ..openers import ImageOpener
2424
from ..nifti1 import Nifti1Header
2525

@@ -240,6 +240,28 @@ def test_reshaped_is_proxy():
240240
prox.reshape((2, -1, 5))
241241

242242

243+
def test_get_obj_dtype():
244+
# Check get_obj_dtype(obj) returns same result as array(obj).dtype
245+
bio = BytesIO()
246+
shape = (2, 3, 4)
247+
hdr = Nifti1Header()
248+
arr = np.arange(24, dtype=np.int16).reshape(shape)
249+
write_raw_data(arr, hdr, bio)
250+
hdr.set_slope_inter(2, 10)
251+
prox = ArrayProxy(bio, hdr)
252+
assert get_obj_dtype(prox) == np.dtype('float64')
253+
assert get_obj_dtype(np.array(prox)) == np.dtype('float64')
254+
hdr.set_slope_inter(1, 0)
255+
prox = ArrayProxy(bio, hdr)
256+
assert get_obj_dtype(prox) == np.dtype('int16')
257+
assert get_obj_dtype(np.array(prox)) == np.dtype('int16')
258+
259+
class ArrGiver:
260+
def __array__(self):
261+
return arr
262+
assert get_obj_dtype(ArrGiver()) == np.dtype('int16')
263+
264+
243265
def test_get_unscaled():
244266
# Test fetch of raw array
245267
class FunkyHeader2(FunkyHeader):

0 commit comments

Comments
 (0)