Skip to content

Commit d337988

Browse files
committed
BF: direct comparison of numpy types failing
Replace with comparison against numpy dtype kinds.
1 parent 9ad693c commit d337988

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

nibabel/tests/test_utils.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@
3030
make_dt_codes,
3131
native_code,
3232
shape_zoom_affine,
33-
rec2dict,
34-
IUINT_TYPES,
35-
FLOAT_TYPES,
36-
NUMERIC_TYPES)
33+
rec2dict)
3734

3835
from ..casting import FloatingError, floor_log2, type_info, best_float
3936

@@ -44,6 +41,12 @@
4441

4542
from ..testing import assert_dt_equal
4643

44+
#: convenience variables for numpy types
45+
FLOAT_TYPES = np.sctypes['float']
46+
CFLOAT_TYPES = np.sctypes['complex'] + FLOAT_TYPES
47+
IUINT_TYPES = np.sctypes['int'] + np.sctypes['uint']
48+
NUMERIC_TYPES = CFLOAT_TYPES + IUINT_TYPES
49+
4750

4851
def test_array_from_file():
4952
shape = (2,3,4)
@@ -56,7 +59,7 @@ def test_array_from_file():
5659
assert_true(buf_chk(in_arr, BytesIO(), None, offset))
5760
# check on real file
5861
fname = 'test.bin'
59-
with InTemporaryDirectory() as tmpdir:
62+
with InTemporaryDirectory():
6063
# fortran ordered
6164
out_buf = open(fname, 'wb')
6265
in_buf = open(fname, 'rb')

nibabel/volumeutils.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@
3333
#: default compression level when writing gz and bz2 files
3434
default_compresslevel = 1
3535

36-
#: convenience variables for numpy types
37-
FLOAT_TYPES = np.sctypes['float']
38-
CFLOAT_TYPES = np.sctypes['complex'] + FLOAT_TYPES
39-
IUINT_TYPES = np.sctypes['int'] + np.sctypes['uint']
40-
NUMERIC_TYPES = CFLOAT_TYPES + IUINT_TYPES
41-
4236

4337
class Recoder(object):
4438
''' class to return canonical code(s) from code or aliases
@@ -618,7 +612,7 @@ def array_to_file(data, fileobj, out_dtype=None, offset=0,
618612
dt_mnmx = _dt_min_max(in_dtype, mn, mx)
619613
# Check what working type we need to cover range
620614
w_type = working_type(in_dtype, slope, inter)
621-
assert w_type in FLOAT_TYPES
615+
assert w_type in np.sctypes['float']
622616
w_type = best_write_scale_ftype(np.array(dt_mnmx, dtype=in_dtype),
623617
slope, inter, w_type)
624618
slope = slope.astype(w_type)
@@ -1237,10 +1231,10 @@ def finite_range(arr):
12371231
# Resort array to slowest->fastest memory change indices
12381232
stride_order = np.argsort(arr.strides)[::-1]
12391233
sarr = arr.transpose(stride_order)
1240-
typ = sarr.dtype.type
1241-
if typ in IUINT_TYPES:
1234+
kind = sarr.dtype.kind
1235+
if kind in 'iu':
12421236
return np.min(sarr), np.max(sarr)
1243-
if typ not in np.sctypes['float']:
1237+
if kind != 'f':
12441238
raise TypeError('Can only handle floats and (u)ints')
12451239
# Deal with 1D arrays in loop below
12461240
sarr = np.atleast_2d(sarr)

0 commit comments

Comments
 (0)