Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STY: Enforce ruff/flake8-comprehensions rules (C4) #1353

Merged
merged 5 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nibabel/brikhead.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def parse_AFNI_header(fobj):
return parse_AFNI_header(src)
# unpack variables in HEAD file
head = fobj.read().split('\n\n')
return {key: value for key, value in map(_unpack_var, head)}
return dict(map(_unpack_var, head))


class AFNIArrayProxy(ArrayProxy):
Expand Down
2 changes: 1 addition & 1 deletion nibabel/casting.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ def able_int_type(values):
>>> able_int_type([-1, 1]) == np.int8
True
"""
if any([v % 1 for v in values]):
if any(v % 1 for v in values):
return None
mn = min(values)
mx = max(values)
Expand Down
6 changes: 3 additions & 3 deletions nibabel/cifti2/tests/test_cifti2.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_cifti2_metadata():
assert len(md) == 1
assert list(iter(md)) == ['a']
assert md['a'] == 'aval'
assert md.data == dict([('a', 'aval')])
assert md.data == {'a': 'aval'}

with pytest.warns(FutureWarning):
md = ci.Cifti2MetaData(metadata={'a': 'aval'})
Expand All @@ -57,7 +57,7 @@ def test_cifti2_metadata():
md['a'] = 'aval'
assert md['a'] == 'aval'
assert len(md) == 1
assert md.data == dict([('a', 'aval')])
assert md.data == {'a': 'aval'}

del md['a']
assert len(md) == 0
Expand Down Expand Up @@ -392,7 +392,7 @@ def test_matrix():
m[0] = mim_1
assert list(m.mapped_indices) == [1]
m.insert(0, mim_0)
assert list(sorted(m.mapped_indices)) == [0, 1]
assert sorted(m.mapped_indices) == [0, 1]
assert h.number_of_mapped_indices == 2
assert h.get_index_map(0) == mim_0
assert h.get_index_map(1) == mim_1
Expand Down
4 changes: 1 addition & 3 deletions nibabel/nicom/dicomwrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,7 @@
frame_slc_pos = [np.inner(ipp, self.slice_normal) for ipp in frame_ipps]
rnd_slc_pos = np.round(frame_slc_pos, 4)
uniq_slc_pos = np.unique(rnd_slc_pos)
pos_ord_map = {
val: order for val, order in zip(uniq_slc_pos, np.argsort(uniq_slc_pos))
}
pos_ord_map = dict(zip(uniq_slc_pos, np.argsort(uniq_slc_pos)))

Check warning on line 688 in nibabel/nicom/dicomwrappers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/nicom/dicomwrappers.py#L688

Added line #L688 was not covered by tests
self._frame_slc_ord = [pos_ord_map[pos] for pos in rnd_slc_pos]
if len(self._frame_slc_ord) > 1:
self._slice_spacing = (
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ exclude = ["doc", "nibabel/externals", "tools", "version.py", "versioneer.py"]
[tool.ruff.lint]
select = [
"B",
"C4",
"F",
"I",
"PLE",
Expand All @@ -135,6 +136,9 @@ ignore = [
"B023", # TODO: enable
"B028",
"B904",
"C401",
"C408",
"C416",
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
"W191",
"E111",
Expand Down
Loading