Skip to content

Commit 9827468

Browse files
committed
TEST: Update tests to match new behavior
1 parent db2f327 commit 9827468

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
@@ -2297,11 +2297,22 @@ def _get_smallest_dtype(
22972297
>>> _get_smallest_dtype(np.array([-65536, 65536]))
22982298
dtype('int32')
22992299
>>> _get_smallest_dtype(np.array([-2147483648, 2147483648]))
2300+
2301+
By default floating point types are not searched:
2302+
23002303
>>> _get_smallest_dtype(np.array([1.]))
2301-
dtype('float32')
23022304
>>> _get_smallest_dtype(np.array([2. ** 1000]))
23032305
>>> _get_smallest_dtype(np.longdouble(2) ** 2000)
23042306
>>> _get_smallest_dtype(np.array([1+0j]))
2307+
2308+
However, this function can be passed "legal" floating point types, and
2309+
the logic works the same.
2310+
2311+
>>> _get_smallest_dtype(np.array([1.]), ftypes=('float32',))
2312+
dtype('float32')
2313+
>>> _get_smallest_dtype(np.array([2. ** 1000]), ftypes=('float32',))
2314+
>>> _get_smallest_dtype(np.longdouble(2) ** 2000, ftypes=('float32',))
2315+
>>> _get_smallest_dtype(np.array([1+0j]), ftypes=('float32',))
23052316
"""
23062317
arr = np.asanyarray(arr)
23072318
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)