From 50a7fb209aca4c6c9122e5e6cf2b8dd68e97151a Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 9 Oct 2024 09:24:21 +0200 Subject: [PATCH] STY: Further simplification Co-authored-by: Chris Markiewicz --- nibabel/tests/test_nifti1.py | 3 +-- nibabel/tests/test_volumeutils.py | 6 +----- nibabel/volumeutils.py | 3 +-- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/nibabel/tests/test_nifti1.py b/nibabel/tests/test_nifti1.py index e7b226187..b54a336ea 100644 --- a/nibabel/tests/test_nifti1.py +++ b/nibabel/tests/test_nifti1.py @@ -538,8 +538,7 @@ def test_slice_times(self): hdr.set_slice_duration(0.1) # We need a function to print out the Nones and floating point # values in a predictable way, for the tests below. - _stringer = lambda val: (val is not None and f'{val:2.1f}') or None - _print_me = lambda s: list(map(_stringer, s)) + _print_me = lambda s: [val if val is None else f'{val:2.1f}' for val in s] # The following examples are from the nifti1.h documentation. hdr['slice_code'] = slice_order_codes['sequential increasing'] assert _print_me(hdr.get_slice_times()) == [ diff --git a/nibabel/tests/test_volumeutils.py b/nibabel/tests/test_volumeutils.py index 4eb6b1d64..86923cc9f 100644 --- a/nibabel/tests/test_volumeutils.py +++ b/nibabel/tests/test_volumeutils.py @@ -607,11 +607,7 @@ def test_a2f_nanpos(): def test_a2f_bad_scaling(): # Test that pathological scalers raise an error - NUMERICAL_TYPES = [ - x - for sublist in (sctypes[key] for key in ('int', 'uint', 'float', 'complex')) - for x in sublist - ] + NUMERICAL_TYPES = [tp for kind in ('int', 'uint', 'float', 'complex') for tp in sctypes[kind]] for in_type, out_type, slope, inter in itertools.product( NUMERICAL_TYPES, NUMERICAL_TYPES, diff --git a/nibabel/volumeutils.py b/nibabel/volumeutils.py index 67a3f9a58..992c16924 100644 --- a/nibabel/volumeutils.py +++ b/nibabel/volumeutils.py @@ -35,8 +35,7 @@ DT = ty.TypeVar('DT', bound=np.generic) sys_is_le = sys.byteorder == 'little' -native_code = (sys_is_le and '<') or '>' -swapped_code = (sys_is_le and '>') or '<' +native_code, swapped_code = ('<', '>') if sys_is_le else ('>', '<') _endian_codes = ( # numpy code, aliases ('<', 'little', 'l', 'le', 'L', 'LE'),