|
21 | 21 | from nibabel.testing import clear_and_catch_warnings
|
22 | 22 | from .test_parse_gifti_fast import (DATA_FILE1, DATA_FILE2, DATA_FILE3,
|
23 | 23 | DATA_FILE4, DATA_FILE5, DATA_FILE6)
|
| 24 | +import itertools |
24 | 25 |
|
25 | 26 |
|
26 | 27 | def test_gifti_image():
|
@@ -400,3 +401,20 @@ def test_data_array_round_trip():
|
400 | 401 | gio = GiftiImage.from_file_map(fmap)
|
401 | 402 | vertices = gio.darrays[0].data
|
402 | 403 | assert_array_equal(vertices, verts)
|
| 404 | + |
| 405 | + |
| 406 | +def test_type_coercion(): |
| 407 | + dtypes = (np.uint8, np.int32, np.int64, np.float32, np.float64) |
| 408 | + encodings = ('ASCII', 'B64BIN', 'B64GZ') |
| 409 | + for data_dtype, darray_dtype, encoding in itertools.product(dtypes, |
| 410 | + dtypes, |
| 411 | + encodings): |
| 412 | + da = GiftiDataArray(np.arange(10).astype(data_dtype), |
| 413 | + encoding=encoding, |
| 414 | + intent='NIFTI_INTENT_NODE_INDEX', |
| 415 | + datatype=darray_dtype) |
| 416 | + gii = GiftiImage(darrays=[da]) |
| 417 | + gii_copy = GiftiImage.from_bytes(gii.to_bytes()) |
| 418 | + da_copy = gii_copy.darrays[0] |
| 419 | + assert_equal(np.dtype(da_copy.data.dtype), np.dtype(darray_dtype)) |
| 420 | + assert_array_equal(da_copy.data, da.data) |
0 commit comments