Skip to content

Commit a982786

Browse files
authored
MAINT: Enable linting with ruff E501 (#29300)
* MAINT: Enforce ruff E501 * fix merge
1 parent c96fcc8 commit a982786

File tree

7 files changed

+68
-47
lines changed

7 files changed

+68
-47
lines changed

benchmarks/benchmarks/bench_linalg.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ def setup(self, dtype):
148148
self.non_contiguous_dim1_small = np.arange(1, 80, 2, dtype=dtype)
149149
self.non_contiguous_dim1 = np.arange(1, 4000, 2, dtype=dtype)
150150
self.non_contiguous_dim2 = np.arange(1, 2400, 2, dtype=dtype).reshape(30, 40)
151-
self.non_contiguous_dim3 = np.arange(1, 48000, 2, dtype=dtype).reshape(20, 30, 40)
151+
152+
non_contiguous_dim3 = np.arange(1, 48000, 2, dtype=dtype)
153+
self.non_contiguous_dim3 = non_contiguous_dim3.reshape(20, 30, 40)
152154

153155
# outer(a,b): trigger sum_of_products_contig_stride0_outcontig_two
154156
def time_einsum_outer(self, dtype):
@@ -180,11 +182,13 @@ def time_einsum_contig_outstride0(self, dtype):
180182

181183
# outer(a,b): non_contiguous arrays
182184
def time_einsum_noncon_outer(self, dtype):
183-
np.einsum("i,j", self.non_contiguous_dim1, self.non_contiguous_dim1, optimize=True)
185+
np.einsum("i,j", self.non_contiguous_dim1,
186+
self.non_contiguous_dim1, optimize=True)
184187

185188
# multiply(a, b):non_contiguous arrays
186189
def time_einsum_noncon_multiply(self, dtype):
187-
np.einsum("..., ...", self.non_contiguous_dim2, self.non_contiguous_dim3, optimize=True)
190+
np.einsum("..., ...", self.non_contiguous_dim2,
191+
self.non_contiguous_dim3, optimize=True)
188192

189193
# sum and multiply:non_contiguous arrays
190194
def time_einsum_noncon_sum_mul(self, dtype):
@@ -200,7 +204,8 @@ def time_einsum_noncon_mul(self, dtype):
200204

201205
# contig_contig_outstride0_two: non_contiguous arrays
202206
def time_einsum_noncon_contig_contig(self, dtype):
203-
np.einsum("ji,i->", self.non_contiguous_dim2, self.non_contiguous_dim1_small, optimize=True)
207+
np.einsum("ji,i->", self.non_contiguous_dim2,
208+
self.non_contiguous_dim1_small, optimize=True)
204209

205210
# sum_of_products_contig_outstride0_one: non_contiguous arrays
206211
def time_einsum_noncon_contig_outstride0(self, dtype):

numpy/_core/tests/test_simd.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ def test_operators_shift(self):
271271
shr = self.shr(vdata_a, count)
272272
assert shr == data_shr_a
273273

274-
# shift by zero or max or out-range immediate constant is not applicable and illogical
274+
# shift by zero or max or out-range immediate constant is not
275+
# applicable and illogical
275276
for count in range(1, self._scalar_size()):
276277
# load to cast
277278
data_shl_a = self.load([a << count for a in data_a])
@@ -419,7 +420,8 @@ def test_sqrt(self):
419420
sqrt = self.sqrt(self.setall(case))
420421
assert sqrt == pytest.approx(data_sqrt, nan_ok=True)
421422

422-
data_sqrt = self.load([math.sqrt(x) for x in data]) # load to truncate precision
423+
# load to truncate precision
424+
data_sqrt = self.load([math.sqrt(x) for x in data])
423425
sqrt = self.sqrt(vdata)
424426
assert sqrt == data_sqrt
425427

@@ -1334,8 +1336,10 @@ def test_mask_conditional(self):
13341336
for sfx in sfxes:
13351337
skip_m = skip_sfx.get(sfx, skip)
13361338
inhr = (cls,)
1337-
attr = {"npyv": targets[target_name], "sfx": sfx, "target_name": target_name}
1338-
tcls = type(f"Test{cls.__name__}_{simd_width}_{target_name}_{sfx}", inhr, attr)
1339+
attr = {"npyv": targets[target_name], "sfx": sfx,
1340+
"target_name": target_name}
1341+
type_name = f"Test{cls.__name__}_{simd_width}_{target_name}_{sfx}"
1342+
tcls = type(type_name, inhr, attr)
13391343
if skip_m:
13401344
pytest.mark.skip(reason=skip_m)(tcls)
13411345
globals()[tcls.__name__] = tcls

numpy/_core/tests/test_ufunc.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,17 +1100,15 @@ def test_output_ellipsis_errors(self):
11001100
match=r"out=\.\.\. is only allowed as a keyword argument."):
11011101
np.add.reduce(1, (), None, ...)
11021102

1103-
with pytest.raises(TypeError,
1104-
match=r"must use `\.\.\.` as `out=\.\.\.` and not per-operand/in a tuple"):
1103+
type_error = r"must use `\.\.\.` as `out=\.\.\.` and not per-operand/in a tuple"
1104+
with pytest.raises(TypeError, match=type_error):
11051105
np.negative(1, out=(...,))
11061106

1107-
with pytest.raises(TypeError,
1108-
match=r"must use `\.\.\.` as `out=\.\.\.` and not per-operand/in a tuple"):
1107+
with pytest.raises(TypeError, match=type_error):
11091108
# We only allow out=... not individual args for now
11101109
np.divmod(1, 2, out=(np.empty(()), ...))
11111110

1112-
with pytest.raises(TypeError,
1113-
match=r"must use `\.\.\.` as `out=\.\.\.` and not per-operand/in a tuple"):
1111+
with pytest.raises(TypeError, match=type_error):
11141112
np.add.reduce(1, out=(...,))
11151113

11161114
def test_axes_argument(self):
@@ -1556,7 +1554,8 @@ def __eq__(self, other):
15561554

15571555
arr1d = np.array([HasComparisons()])
15581556
assert_equal(arr1d == arr1d, np.array([True]))
1559-
assert_equal(np.equal(arr1d, arr1d), np.array([True])) # normal behavior is a cast
1557+
# normal behavior is a cast
1558+
assert_equal(np.equal(arr1d, arr1d), np.array([True]))
15601559
assert_equal(np.equal(arr1d, arr1d, dtype=object), np.array(['==']))
15611560

15621561
def test_object_array_reduction(self):

numpy/_core/tests/test_umath_accuracy.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,16 @@ def test_validate_transcendentals(self):
6868
npfunc = getattr(np, npname)
6969
for datatype in np.unique(data['type']):
7070
data_subset = data[data['type'] == datatype]
71-
inval = np.array(str_to_float(data_subset['input'].astype(str), data_subset['type'].astype(str)), dtype=eval(datatype))
72-
outval = np.array(str_to_float(data_subset['output'].astype(str), data_subset['type'].astype(str)), dtype=eval(datatype))
71+
data_input_str = data_subset['input'].astype(str)
72+
data_output_str = data_subset['output'].astype(str)
73+
data_type_str = data_subset['type'].astype(str)
74+
75+
inval = np.array(str_to_float(data_input_str,
76+
data_type_str),
77+
dtype=eval(datatype))
78+
outval = np.array(str_to_float(data_output_str,
79+
data_type_str),
80+
dtype=eval(datatype))
7381
perm = np.random.permutation(len(inval))
7482
inval = inval[perm]
7583
outval = outval[perm]

numpy/_core/tests/test_umath_complex.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -562,31 +562,35 @@ class TestSpecialComplexAVX:
562562
@pytest.mark.parametrize("stride", [-4, -2, -1, 1, 2, 4])
563563
@pytest.mark.parametrize("astype", [np.complex64, np.complex128])
564564
def test_array(self, stride, astype):
565-
arr = np.array([complex(np.nan, np.nan),
566-
complex(np.nan, np.inf),
567-
complex(np.inf, np.nan),
568-
complex(np.inf, np.inf),
569-
complex(0., np.inf),
570-
complex(np.inf, 0.),
571-
complex(0., 0.),
572-
complex(0., np.nan),
573-
complex(np.nan, 0.)], dtype=astype)
574-
abs_true = np.array([np.nan, np.inf, np.inf, np.inf, np.inf, np.inf, 0., np.nan, np.nan], dtype=arr.real.dtype)
575-
sq_true = np.array([complex(np.nan, np.nan),
576-
complex(np.nan, np.nan),
577-
complex(np.nan, np.nan),
578-
complex(np.nan, np.inf),
579-
complex(-np.inf, np.nan),
580-
complex(np.inf, np.nan),
581-
complex(0., 0.),
582-
complex(np.nan, np.nan),
583-
complex(np.nan, np.nan)], dtype=astype)
565+
nan = np.nan
566+
inf = np.inf
567+
arr = np.array([complex(nan, nan),
568+
complex(nan, inf),
569+
complex(inf, nan),
570+
complex(inf, inf),
571+
complex(0., inf),
572+
complex(inf, 0.),
573+
complex(0., 0.),
574+
complex(0., nan),
575+
complex(nan, 0.)], dtype=astype)
576+
abs_true = np.array([nan, inf, inf, inf, inf, inf, 0., nan, nan],
577+
dtype=arr.real.dtype)
578+
sq_true = np.array([complex(nan, nan),
579+
complex(nan, nan),
580+
complex(nan, nan),
581+
complex(nan, inf),
582+
complex(-inf, nan),
583+
complex(inf, nan),
584+
complex(0., 0.),
585+
complex(nan, nan),
586+
complex(nan, nan)], dtype=astype)
584587
with np.errstate(invalid='ignore'):
585588
assert_equal(np.abs(arr[::stride]), abs_true[::stride])
586589
assert_equal(np.square(arr[::stride]), sq_true[::stride])
587590

588591
class TestComplexAbsoluteAVX:
589-
@pytest.mark.parametrize("arraysize", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 18, 19])
592+
@pytest.mark.parametrize("arraysize",
593+
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 18, 19])
590594
@pytest.mark.parametrize("stride", [-4, -3, -2, -1, 1, 2, 3, 4])
591595
@pytest.mark.parametrize("astype", [np.complex64, np.complex128])
592596
# test to ensure masking and strides work as intended in the AVX implementation

numpy/tests/test_configtool.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
PKG_CONFIG_DIR = NUMPY_ROOT / '_core' / 'lib' / 'pkgconfig'
1616

1717

18-
@pytest.mark.skipif(not IS_INSTALLED, reason="`numpy-config` not expected to be installed")
19-
@pytest.mark.skipif(IS_WASM, reason="wasm interpreter cannot start subprocess")
18+
@pytest.mark.skipif(not IS_INSTALLED,
19+
reason="`numpy-config` not expected to be installed")
20+
@pytest.mark.skipif(IS_WASM,
21+
reason="wasm interpreter cannot start subprocess")
2022
class TestNumpyConfig:
2123
def check_numpyconfig(self, arg):
2224
p = subprocess.run(['numpy-config', arg], capture_output=True, text=True)
@@ -36,13 +38,15 @@ def test_configtool_pkgconfigdir(self):
3638
assert pathlib.Path(stdout) == PKG_CONFIG_DIR
3739

3840

39-
@pytest.mark.skipif(not IS_INSTALLED, reason="numpy must be installed to check its entrypoints")
41+
@pytest.mark.skipif(not IS_INSTALLED,
42+
reason="numpy must be installed to check its entrypoints")
4043
def test_pkg_config_entrypoint():
4144
(entrypoint,) = importlib.metadata.entry_points(group='pkg_config', name='numpy')
4245
assert entrypoint.value == numpy._core.lib.pkgconfig.__name__
4346

4447

45-
@pytest.mark.skipif(not IS_INSTALLED, reason="numpy.pc is only available when numpy is installed")
48+
@pytest.mark.skipif(not IS_INSTALLED,
49+
reason="numpy.pc is only available when numpy is installed")
4650
@pytest.mark.skipif(IS_EDITABLE, reason="editable installs don't have a numpy.pc")
4751
def test_pkg_config_config_exists():
4852
assert PKG_CONFIG_DIR.joinpath('numpy.pc').is_file()

ruff.toml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ ignore = [
7272
"bench_*.py" = ["B015", "B018"]
7373
"test*.py" = ["B015", "B018", "E201", "E714"]
7474

75-
"benchmarks/benchmarks/bench_linalg.py" = ["E501"]
7675
"numpy/_core/tests/test_arrayprint.py" = ["E501"]
7776
"numpy/_core/tests/test_cpu_dispatcher.py" = ["E501"]
7877
"numpy/_core/tests/test_cpu_features.py" = ["E501"]
@@ -81,17 +80,15 @@ ignore = [
8180
"numpy/_core/tests/test_einsum.py" = ["E501"]
8281
"numpy/_core/tests/test_multiarray.py" = ["E501"]
8382
"numpy/_core/tests/test_nditer*py" = ["E501"]
84-
"numpy/_core/tests/test_ufunc*py" = ["E501"]
85-
"numpy/_core/tests/test_umath*py" = ["E501"]
86-
"numpy/_core/tests/test_numeric*.py" = ["E501"]
83+
"numpy/_core/tests/test_umath.py" = ["E501"]
84+
"numpy/_core/tests/test_numeric.py" = ["E501"]
85+
"numpy/_core/tests/test_numerictypes.py" = ["E501"]
8786
"numpy/_core/tests/test_regression.py" = ["E501"]
88-
"numpy/_core/tests/test_simd.py" = ["E501"]
8987
"numpy/_core/_add_newdocs.py" = ["E501"]
9088
"numpy/_core/_add_newdocs_scalars.py" = ["E501"]
9189
"numpy/_core/code_generators/generate_umath.py" = ["E501"]
9290
"numpy/lib/tests/test_format.py" = ["E501"]
9391
"numpy/linalg/tests/test_linalg.py" = ["E501"]
94-
"numpy/tests/test_configtool.py" = ["E501"]
9592
"numpy/f2py/*py" = ["E501"]
9693
# for typing related files we follow https://typing.python.org/en/latest/guides/writing_stubs.html#maximum-line-length
9794
"numpy/_typing/_array_like.py" = ["E501"]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy