Skip to content

Commit 0f746c0

Browse files
larsonereffigies
andauthored
Apply suggestions from code review
Co-authored-by: Chris Markiewicz <[email protected]>
1 parent d4596b7 commit 0f746c0

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

nibabel/casting.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class CastingError(Exception):
4545
],
4646
'others': [bool, object, bytes, str, np.void],
4747
}
48-
# fmt: off
4948
sctypes_aliases = {
5049
getattr(np, dtype)
5150
for dtype in (
@@ -59,8 +58,7 @@ class CastingError(Exception):
5958
'object_', 'void',
6059
)
6160
if hasattr(np, dtype)
62-
}
63-
# fmt: on
61+
} # fmt:skip
6462

6563

6664
def float_to_int(arr, int_type, nan2zero=True, infmax=False):
@@ -492,9 +490,6 @@ def int_to_float(val, flt_type):
492490
return flt_type(val)
493491
# The following works around a nasty numpy 1.4.1 bug such that:
494492
# >>> int(np.uint32(2**32-1)
495-
# -1
496-
if not isinstance(val, Integral):
497-
val = int(str(val))
498493
val = int(val)
499494
faval = np.longdouble(0)
500495
while val != 0:

nibabel/conftest.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import nibabel.nicom
77

88

9-
def pytest_configure(config):
10-
"""Configure pytest options."""
11-
if int(np.__version__[0]) >= 2:
12-
np.set_printoptions(legacy=125)
9+
@pytest.fixture(scope='session', autouse=True)
10+
def legacy_printoptions():
11+
from packaging.version import Version
12+
if Version(np.__version__) >= Version('1.22'):
13+
np.set_printoptions(legacy='1.21')

nibabel/quaternions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929

3030
import numpy as np
3131

32-
MAX_FLOAT = np.finfo(float).max
32+
from .casting import sctypes
33+
34+
MAX_FLOAT = sctypes['float'][-1]
3335
FLOAT_EPS = np.finfo(float).eps
3436

3537

nibabel/tests/test_volumeutils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,12 @@ def test_a2f_scaled_unscaled():
543543
NUMERIC_TYPES, NUMERIC_TYPES, (0, 0.5, -1, 1), (1, 0.5, 2)
544544
):
545545
mn_in, mx_in = _dt_min_max(in_dtype)
546-
nan_val = np.nan if in_dtype in CFLOAT_TYPES else 10
547-
mn = 0 if np.dtype(in_dtype).kind == "u" else 1
548-
arr = np.array([mn_in, mn, 0, 1, mx_in, nan_val], dtype=in_dtype)
546+
vals = [mn_in, 0, 1, mx_in]
547+
if np.dtype(in_dtype).kind != 'u':
548+
vals.append(-1)
549+
if in_dtype in CFLOAT_TYPES:
550+
vals.append(np.nan)
551+
arr = np.array(vals, dtype=in_dtype)
549552
mn_out, mx_out = _dt_min_max(out_dtype)
550553
# 0 when scaled to output will also be the output value for NaN
551554
nan_fill = -intercept / divslope

0 commit comments

Comments
 (0)