diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8dd5d0547..aefad8f42 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,9 +20,6 @@ repos: exclude: = ["doc", "tools"] - id: ruff-format exclude: = ["doc", "tools"] - - id: ruff - args: [ --select, ISC001, --fix ] - exclude: = ["doc", "tools"] - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.14.1 hooks: diff --git a/nibabel/benchmarks/bench_arrayproxy_slicing.py b/nibabel/benchmarks/bench_arrayproxy_slicing.py index 808a22739..5da6c578f 100644 --- a/nibabel/benchmarks/bench_arrayproxy_slicing.py +++ b/nibabel/benchmarks/bench_arrayproxy_slicing.py @@ -99,7 +99,7 @@ def fmt_sliceobj(sliceobj): return f'[{", ".join(slcstr)}]' with InTemporaryDirectory(): - print(f'Generating test data... ({int(round(np.prod(SHAPE) * 4 / 1048576.0))} MB)') + print(f'Generating test data... ({round(np.prod(SHAPE) * 4 / 1048576.0)} MB)') data = np.array(np.random.random(SHAPE), dtype=np.float32) diff --git a/nibabel/cmdline/diff.py b/nibabel/cmdline/diff.py index 55f827e97..6a44f3ce5 100755 --- a/nibabel/cmdline/diff.py +++ b/nibabel/cmdline/diff.py @@ -309,11 +309,11 @@ def display_diff(files, diff): item_str = str(item) # Value might start/end with some invisible spacing characters so we # would "condition" it on both ends a bit - item_str = re.sub('^[ \t]+', '<', item_str) - item_str = re.sub('[ \t]+$', '>', item_str) + item_str = re.sub(r'^[ \t]+', '<', item_str) + item_str = re.sub(r'[ \t]+$', '>', item_str) # and also replace some other invisible symbols with a question # mark - item_str = re.sub('[\x00]', '?', item_str) + item_str = re.sub(r'[\x00]', '?', item_str) output += value_width.format(item_str) output += '\n' diff --git a/nibabel/cmdline/utils.py b/nibabel/cmdline/utils.py index 298b6a5ad..824ed677a 100644 --- a/nibabel/cmdline/utils.py +++ b/nibabel/cmdline/utils.py @@ -53,7 +53,7 @@ def table2string(table, out=None): table[i] += [''] * (nelements_max - len(table_)) # eat whole entry while computing width for @w (for wide) - markup_strip = re.compile('^@([lrc]|w.*)') + markup_strip = re.compile(r'^@([lrc]|w.*)') col_width = [max(len(markup_strip.sub('', x)) for x in column) for column in zip(*table)] trans = str.maketrans('lrcw', '<>^^') lines = [] diff --git a/nibabel/nicom/dicomwrappers.py b/nibabel/nicom/dicomwrappers.py index 622ab0927..26ca75b15 100755 --- a/nibabel/nicom/dicomwrappers.py +++ b/nibabel/nicom/dicomwrappers.py @@ -153,11 +153,11 @@ def vendor(self): # Look at manufacturer tag first mfgr = self.get('Manufacturer') if mfgr: - if re.search('Siemens', mfgr, re.IGNORECASE): + if re.search(r'Siemens', mfgr, re.IGNORECASE): return Vendor.SIEMENS - if re.search('Philips', mfgr, re.IGNORECASE): + if re.search(r'Philips', mfgr, re.IGNORECASE): return Vendor.PHILIPS - if re.search('GE Medical', mfgr, re.IGNORECASE): + if re.search(r'GE Medical', mfgr, re.IGNORECASE): return Vendor.GE # Next look at UID prefixes for uid_src in ('StudyInstanceUID', 'SeriesInstanceUID', 'SOPInstanceUID'): diff --git a/nibabel/nicom/tests/test_utils.py b/nibabel/nicom/tests/test_utils.py index 4f0d7e68d..bdf95bbbe 100644 --- a/nibabel/nicom/tests/test_utils.py +++ b/nibabel/nicom/tests/test_utils.py @@ -15,7 +15,7 @@ def test_find_private_section_real(): # On real data first assert fps(DATA, 0x29, 'SIEMENS CSA HEADER') == 0x1000 assert fps(DATA, 0x29, b'SIEMENS CSA HEADER') == 0x1000 - assert fps(DATA, 0x29, re.compile('SIEMENS CSA HEADER')) == 0x1000 + assert fps(DATA, 0x29, re.compile(r'SIEMENS CSA HEADER')) == 0x1000 assert fps(DATA, 0x29, 'NOT A HEADER') is None assert fps(DATA, 0x29, 'SIEMENS MEDCOM HEADER2') == 0x1100 assert fps(DATA_PHILIPS, 0x29, 'SIEMENS CSA HEADER') == None @@ -55,7 +55,7 @@ def test_find_private_section_fake(): ds.add_new((0x11, 0x15), 'LO', b'far section') assert fps(ds, 0x11, 'far section') == 0x1500 # More than one match - find the first. - assert fps(ds, 0x11, re.compile('(another|third) section')) == 0x1100 + assert fps(ds, 0x11, re.compile(r'(another|third) section')) == 0x1100 # The signalling element number must be <= 0xFF ds = pydicom.dataset.Dataset({}) ds.add_new((0x11, 0xFF), 'LO', b'some section') diff --git a/nibabel/tests/test_analyze.py b/nibabel/tests/test_analyze.py index befc920f1..85669b366 100644 --- a/nibabel/tests/test_analyze.py +++ b/nibabel/tests/test_analyze.py @@ -497,7 +497,7 @@ def test_str(self): hdr = self.header_class() s1 = str(hdr) # check the datacode recoding - rexp = re.compile('^datatype +: float32', re.MULTILINE) + rexp = re.compile(r'^datatype +: float32', re.MULTILINE) assert rexp.search(s1) is not None def test_from_header(self): diff --git a/nibabel/tests/test_fileslice.py b/nibabel/tests/test_fileslice.py index 355743b04..ae842217f 100644 --- a/nibabel/tests/test_fileslice.py +++ b/nibabel/tests/test_fileslice.py @@ -489,16 +489,16 @@ def test_optimize_read_slicers(): (slice(None),), ) # Check gap threshold with 3D - _depends0 = partial(threshold_heuristic, skip_thresh=10 * 4 - 1) - _depends1 = partial(threshold_heuristic, skip_thresh=10 * 4) + depends0 = partial(threshold_heuristic, skip_thresh=10 * 4 - 1) + depends1 = partial(threshold_heuristic, skip_thresh=10 * 4) assert optimize_read_slicers( - (slice(9), slice(None), slice(None)), (10, 6, 2), 4, _depends0 + (slice(9), slice(None), slice(None)), (10, 6, 2), 4, depends0 ) == ((slice(None), slice(None), slice(None)), (slice(0, 9, 1), slice(None), slice(None))) assert optimize_read_slicers( - (slice(None), slice(5), slice(None)), (10, 6, 2), 4, _depends0 + (slice(None), slice(5), slice(None)), (10, 6, 2), 4, depends0 ) == ((slice(None), slice(0, 5, 1), slice(None)), (slice(None), slice(None), slice(None))) assert optimize_read_slicers( - (slice(None), slice(5), slice(None)), (10, 6, 2), 4, _depends1 + (slice(None), slice(5), slice(None)), (10, 6, 2), 4, depends1 ) == ((slice(None), slice(None), slice(None)), (slice(None), slice(0, 5, 1), slice(None))) # Check longs as integer slices sn = slice(None) diff --git a/nibabel/tests/test_loadsave.py b/nibabel/tests/test_loadsave.py index d039263bd..035cbb56c 100644 --- a/nibabel/tests/test_loadsave.py +++ b/nibabel/tests/test_loadsave.py @@ -88,7 +88,7 @@ def test_load_bad_compressed_extension(tmp_path, extension): pytest.skip() file_path = tmp_path / f'img.nii{extension}' file_path.write_bytes(b'bad') - with pytest.raises(ImageFileError, match='.*is not a .* file'): + with pytest.raises(ImageFileError, match=r'.*is not a .* file'): load(file_path) @@ -99,7 +99,7 @@ def test_load_good_extension_with_bad_data(tmp_path, extension): file_path = tmp_path / f'img.nii{extension}' with Opener(file_path, 'wb') as fobj: fobj.write(b'bad') - with pytest.raises(ImageFileError, match='Cannot work out file type of .*'): + with pytest.raises(ImageFileError, match=r'Cannot work out file type of .*'): load(file_path) diff --git a/nibabel/tests/test_nifti1.py b/nibabel/tests/test_nifti1.py index 286e6beef..acdcb337b 100644 --- a/nibabel/tests/test_nifti1.py +++ b/nibabel/tests/test_nifti1.py @@ -538,11 +538,11 @@ 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: f'{val:2.1f}' if val is not None else None - _print_me = lambda s: list(map(_stringer, s)) + stringer = lambda val: f'{val:2.1f}' if val is not None else None + print_me = lambda s: list(map(stringer, 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()) == [ + assert print_me(hdr.get_slice_times()) == [ '0.0', '0.1', '0.2', @@ -553,17 +553,17 @@ def test_slice_times(self): ] hdr['slice_start'] = 1 hdr['slice_end'] = 5 - assert _print_me(hdr.get_slice_times()) == [None, '0.0', '0.1', '0.2', '0.3', '0.4', None] + assert print_me(hdr.get_slice_times()) == [None, '0.0', '0.1', '0.2', '0.3', '0.4', None] hdr['slice_code'] = slice_order_codes['sequential decreasing'] - assert _print_me(hdr.get_slice_times()) == [None, '0.4', '0.3', '0.2', '0.1', '0.0', None] + assert print_me(hdr.get_slice_times()) == [None, '0.4', '0.3', '0.2', '0.1', '0.0', None] hdr['slice_code'] = slice_order_codes['alternating increasing'] - assert _print_me(hdr.get_slice_times()) == [None, '0.0', '0.3', '0.1', '0.4', '0.2', None] + assert print_me(hdr.get_slice_times()) == [None, '0.0', '0.3', '0.1', '0.4', '0.2', None] hdr['slice_code'] = slice_order_codes['alternating decreasing'] - assert _print_me(hdr.get_slice_times()) == [None, '0.2', '0.4', '0.1', '0.3', '0.0', None] + assert print_me(hdr.get_slice_times()) == [None, '0.2', '0.4', '0.1', '0.3', '0.0', None] hdr['slice_code'] = slice_order_codes['alternating increasing 2'] - assert _print_me(hdr.get_slice_times()) == [None, '0.2', '0.0', '0.3', '0.1', '0.4', None] + assert print_me(hdr.get_slice_times()) == [None, '0.2', '0.0', '0.3', '0.1', '0.4', None] hdr['slice_code'] = slice_order_codes['alternating decreasing 2'] - assert _print_me(hdr.get_slice_times()) == [None, '0.4', '0.1', '0.3', '0.0', '0.2', None] + assert print_me(hdr.get_slice_times()) == [None, '0.4', '0.1', '0.3', '0.0', '0.2', None] # test set hdr = self.header_class() hdr.set_dim_info(slice=2) diff --git a/nibabel/viewers.py b/nibabel/viewers.py index 185a3e1f3..7f7f1d5a4 100644 --- a/nibabel/viewers.py +++ b/nibabel/viewers.py @@ -373,11 +373,11 @@ def set_volume_idx(self, v): def _set_volume_index(self, v, update_slices=True): """Set the plot data using a volume index""" - v = self._data_idx[3] if v is None else int(round(v)) + v = self._data_idx[3] if v is None else round(v) if v == self._data_idx[3]: return max_ = np.prod(self._volume_dims) - self._data_idx[3] = max(min(int(round(v)), max_ - 1), 0) + self._data_idx[3] = max(min(round(v), max_ - 1), 0) idx = (slice(None), slice(None), slice(None)) if self._data.ndim > 3: idx = idx + tuple(np.unravel_index(self._data_idx[3], self._volume_dims)) @@ -401,7 +401,7 @@ def _set_position(self, x, y, z, notify=True): idxs = np.dot(self._inv_affine, self._position)[:3] idxs_new_order = idxs[self._order] for ii, (size, idx) in enumerate(zip(self._sizes, idxs_new_order)): - self._data_idx[ii] = max(min(int(round(idx)), size - 1), 0) + self._data_idx[ii] = max(min(round(idx), size - 1), 0) for ii in range(3): # sagittal: get to S/A # coronal: get to S/L