|
19 | 19 |
|
20 | 20 | import numpy as np |
21 | 21 |
|
22 | | -from ..arrayproxy import (ArrayProxy, is_proxy, reshape_dataobj) |
| 22 | +from ..arrayproxy import (ArrayProxy, is_proxy, reshape_dataobj, get_obj_dtype) |
23 | 23 | from ..openers import ImageOpener |
24 | 24 | from ..nifti1 import Nifti1Header |
25 | 25 |
|
@@ -240,6 +240,28 @@ def test_reshaped_is_proxy(): |
240 | 240 | prox.reshape((2, -1, 5)) |
241 | 241 |
|
242 | 242 |
|
| 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 | + |
243 | 265 | def test_get_unscaled(): |
244 | 266 | # Test fetch of raw array |
245 | 267 | class FunkyHeader2(FunkyHeader): |
|
0 commit comments