Skip to content

Commit a8b6ff9

Browse files
committed
TEST: Update tests to match new behavior
1 parent 5698d0d commit a8b6ff9

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

nibabel/nifti1.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2301,11 +2301,22 @@ def _get_smallest_dtype(
23012301
>>> _get_smallest_dtype(np.array([-65536, 65536]))
23022302
dtype('int32')
23032303
>>> _get_smallest_dtype(np.array([-2147483648, 2147483648]))
2304+
2305+
By default floating point types are not searched:
2306+
23042307
>>> _get_smallest_dtype(np.array([1.]))
2305-
dtype('float32')
23062308
>>> _get_smallest_dtype(np.array([2. ** 1000]))
23072309
>>> _get_smallest_dtype(np.longdouble(2) ** 2000)
23082310
>>> _get_smallest_dtype(np.array([1+0j]))
2311+
2312+
However, this function can be passed "legal" floating point types, and
2313+
the logic works the same.
2314+
2315+
>>> _get_smallest_dtype(np.array([1.]), ftypes=('float32',))
2316+
dtype('float32')
2317+
>>> _get_smallest_dtype(np.array([2. ** 1000]), ftypes=('float32',))
2318+
>>> _get_smallest_dtype(np.longdouble(2) ** 2000, ftypes=('float32',))
2319+
>>> _get_smallest_dtype(np.array([1+0j]), ftypes=('float32',))
23092320
"""
23102321
arr = np.asanyarray(arr)
23112322
if np.issubdtype(arr.dtype, np.floating):

nibabel/tests/test_nifti1.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,11 +1121,20 @@ def test_write_scaling(self):
11211121

11221122
def test_dynamic_dtype_aliases(self):
11231123
for in_dt, mn, mx, alias, effective_dt in [
1124-
(np.int64, 0, 255, 'compat', np.uint8),
1125-
(np.int64, 0, 256, 'compat', np.int16),
1126-
(np.int64, -1, 255, 'compat', np.int16),
1127-
(np.int64, 0, 32768, 'compat', np.int32),
1128-
(np.int64, 0, 4294967296, 'compat', None),
1124+
(np.uint8, 0, 255, 'compat', np.uint8),
1125+
(np.int8, 0, 127, 'compat', np.uint8),
1126+
(np.int8, -128, 127, 'compat', np.int16),
1127+
(np.int16, -32768, 32767, 'compat', np.int16),
1128+
(np.uint16, 0, 32767, 'compat', np.int16),
1129+
(np.uint16, 0, 65535, 'compat', np.int32),
1130+
(np.int32, -2**31, 2**31-1, 'compat', np.int32),
1131+
(np.uint32, 0, 2**31-1, 'compat', np.int32),
1132+
(np.uint32, 0, 2**32-1, 'compat', None),
1133+
(np.int64, -2**31, 2**31-1, 'compat', np.int32),
1134+
(np.uint64, 0, 2**31-1, 'compat', np.int32),
1135+
(np.int64, 0, 2**32-1, 'compat', None),
1136+
(np.uint64, 0, 2**32-1, 'compat', None),
1137+
(np.float32, 0, 1e30, 'compat', np.float32),
11291138
(np.float64, 0, 1e30, 'compat', np.float32),
11301139
(np.float64, 0, 1e40, 'compat', None),
11311140
(np.int64, 0, 255, 'smallest', np.uint8),

0 commit comments

Comments
 (0)