Skip to content

Commit 17af48a

Browse files
STY: Enforce ruff/pycodestyle warnings (W) (numpy#28725)
* STY: Apply ruff/pycodestyle whitespace rules W191, W291, W292, W293, W391
1 parent b769da9 commit 17af48a

30 files changed

+47
-64
lines changed

benchmarks/benchmarks/bench_function_base.py

-1
Original file line numberDiff line numberDiff line change
@@ -376,4 +376,3 @@ def time_interleaved_ones_x4(self):
376376

377377
def time_interleaved_ones_x8(self):
378378
np.where(self.rep_ones_8)
379-

benchmarks/benchmarks/bench_linalg.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,14 @@ def __init__(self):
251251
}
252252

253253
self.params = [list(self.args_map.keys())]
254-
254+
255255
def setup(self, configuration):
256256
m, p, n, batch_size = self.args_map[configuration]
257257

258258
self.a1raw = np.random.rand(batch_size * m * 2 * n).reshape(
259259
(batch_size, m, 2 * n)
260260
)
261-
261+
262262
self.a1 = self.a1raw[:, :, ::2]
263263

264264
self.a2 = np.random.rand(batch_size * n * p).reshape(

benchmarks/benchmarks/bench_polynomial.py

-2
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,3 @@ def time_polynomial_evaluation_array_1000(self):
2525

2626
def time_polynomial_addition(self):
2727
_ = self.polynomial_degree2 + self.polynomial_degree2
28-
29-

doc/conftest.py

-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,3 @@ def check_output(self, want, got, optionflags):
2929
def add_np(doctest_namespace):
3030
numpy.random.seed(1)
3131
doctest_namespace['np'] = numpy
32-

doc/neps/nep-0016-benchmark.py

-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,3 @@ def t(name, statement):
4747
t("ABC, False", "isinstance(not_array, ArrayBase)")
4848
t("ABC, True, via inheritance", "isinstance(abc_array_1, ArrayBase)")
4949
t("ABC, True, via register", "isinstance(abc_array_2, ArrayBase)")
50-

doc/preprocess.py

-1
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,3 @@ def doxy_config(root_path):
4646

4747
if __name__ == "__main__":
4848
main()
49-

doc/source/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ def setup(app):
441441
# -----------------------------------------------------------------------------
442442
coverage_ignore_modules = []
443443
coverage_ignore_functions = [
444-
'test($|_)', '(some|all)true', 'bitwise_not', 'cumproduct', 'pkgload', 'generic\\.'
444+
'test($|_)', '(some|all)true', 'bitwise_not', 'cumproduct', 'pkgload', 'generic\\.'
445445
]
446446
coverage_ignore_classes = []
447447

@@ -507,7 +507,7 @@ def _get_c_source_file(obj):
507507
# todo: come up with a better way to generate these
508508
return None
509509

510-
def linkcode_resolve(domain, info):
510+
def linkcode_resolve(domain, info):
511511
"""
512512
Determine the URL corresponding to Python object
513513
"""

doc/source/reference/random/performance.py

-3
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,3 @@
8181
xplat = xplat.T.copy()
8282
xplat['Overall'] = overall
8383
print(xplat.T.round(1))
84-
85-
86-

doc/source/reference/simd/gen_features.py

-2
Original file line numberDiff line numberDiff line change
@@ -192,5 +192,3 @@ def wrapper_tab(title, table, tab_size=4):
192192
title = f"On {arch_pname}::{pretty_names.get(cc, cc)}"
193193
table = Features(arch, cc).table_diff(Features(arch, "gcc"))
194194
fd.write(wrapper_section(title, table))
195-
196-

numpy/_core/numeric.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ def tensordot(a, b, axes=2):
10241024
first tensor, followed by the non-contracted axes of the second.
10251025
10261026
Examples
1027-
--------
1027+
--------
10281028
An example on integer_like:
10291029
10301030
>>> a_0 = np.array([[1, 2], [3, 4]])
@@ -1055,9 +1055,9 @@ def tensordot(a, b, axes=2):
10551055
[4664., 5018.],
10561056
[4796., 5162.],
10571057
[4928., 5306.]])
1058-
1058+
10591059
A slower but equivalent way of computing the same...
1060-
1060+
10611061
>>> d = np.zeros((5,2))
10621062
>>> for i in range(5):
10631063
... for j in range(2):

numpy/_core/tests/test_casting_floatingpoint_errors.py

-1
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,3 @@ def test_floatingpoint_errors_casting(dtype, value):
151151
with np.errstate(all="raise"):
152152
with pytest.raises(FloatingPointError, match=match):
153153
operation()
154-

numpy/_core/tests/test_casting_unittests.py

-1
Original file line numberDiff line numberDiff line change
@@ -816,4 +816,3 @@ def test_nonstandard_bool_to_other(self, dtype):
816816
res = nonstandard_bools.astype(dtype)
817817
expected = [0, 1, 1]
818818
assert_array_equal(res, expected)
819-

numpy/_core/tests/test_datetime.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ def test_timedelta_divmod(self, op1, op2):
14001400
@pytest.mark.parametrize("op1, op2", [
14011401
# Y and M are incompatible with all units except Y and M
14021402
(np.timedelta64(1, 'Y'), np.timedelta64(1, 's')),
1403-
(np.timedelta64(1, 'D'), np.timedelta64(1, 'M')),
1403+
(np.timedelta64(1, 'D'), np.timedelta64(1, 'M')),
14041404
])
14051405
def test_timedelta_divmod_typeerror(self, op1, op2):
14061406
assert_raises(TypeError, np.divmod, op1, op2)

numpy/_core/tests/test_einsum.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def test_einsum_sorting_behavior(self):
116116
# Additional Check: Ensure dimensions correspond correctly to indices
117117
# Generate expected mapping of dimensions to indices
118118
expected_indices = [
119-
chr(i + ord('A')) if i < 26 else chr(i - 26 + ord('a'))
119+
chr(i + ord('A')) if i < 26 else chr(i - 26 + ord('a'))
120120
for i in range(n2)
121121
]
122122
assert_equal(
@@ -1308,4 +1308,4 @@ def inner(*inputs, out):
13081308
res = np.einsum("i->", np.broadcast_to(np.array(value), num)) / num
13091309

13101310
# At with GROWINNER 11 decimals succeed (larger will be less)
1311-
assert_almost_equal(res, value, decimal=15)
1311+
assert_almost_equal(res, value, decimal=15)

numpy/_core/tests/test_multiarray.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -10449,7 +10449,7 @@ def test_to_device(self):
1044910449

1045010450
def test_array_interface_excess_dimensions_raises():
1045110451
"""Regression test for gh-27949: ensure too many dims raises ValueError instead of segfault."""
10452-
10452+
1045310453
# Dummy object to hold a custom __array_interface__
1045410454
class DummyArray:
1045510455
def __init__(self, interface):
@@ -10461,9 +10461,9 @@ def __init__(self, interface):
1046110461
interface = dict(base.__array_interface__)
1046210462

1046310463
# Modify the shape to exceed NumPy's dimension limit (NPY_MAXDIMS, typically 64)
10464-
interface['shape'] = tuple([1] * 136) # match the original bug report
10464+
interface['shape'] = tuple([1] * 136) # match the original bug report
1046510465

1046610466
dummy = DummyArray(interface)
1046710467
# Now, using np.asanyarray on this dummy should trigger a ValueError (not segfault)
1046810468
with pytest.raises(ValueError, match="dimensions must be within"):
10469-
np.asanyarray(dummy)
10469+
np.asanyarray(dummy)

numpy/_core/tests/test_scalarprint.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -217,21 +217,21 @@ def test_dragon4(self):
217217

218218
available_float_dtypes = [np.float16, np.float32, np.float64, np.float128]\
219219
if hasattr(np, 'float128') else [np.float16, np.float32, np.float64]
220-
220+
221221
@pytest.mark.parametrize("tp", available_float_dtypes)
222222
def test_dragon4_positional_interface(self, tp):
223223
# test is flaky for musllinux on np.float128
224224
if IS_MUSL and tp == np.float128:
225225
pytest.skip("Skipping flaky test of float128 on musllinux")
226-
226+
227227
fpos = np.format_float_positional
228-
228+
229229
# test padding
230230
assert_equal(fpos(tp('1.0'), pad_left=4, pad_right=4), " 1. ")
231231
assert_equal(fpos(tp('-1.0'), pad_left=4, pad_right=4), " -1. ")
232232
assert_equal(fpos(tp('-10.2'),
233233
pad_left=4, pad_right=4), " -10.2 ")
234-
234+
235235
# test fixed (non-unique) mode
236236
assert_equal(fpos(tp('1.0'), unique=False, precision=4), "1.0000")
237237

@@ -240,7 +240,7 @@ def test_dragon4_positional_interface_trim(self, tp):
240240
# test is flaky for musllinux on np.float128
241241
if IS_MUSL and tp == np.float128:
242242
pytest.skip("Skipping flaky test of float128 on musllinux")
243-
243+
244244
fpos = np.format_float_positional
245245
# test trimming
246246
# trim of 'k' or '.' only affects non-unique mode, since unique
@@ -265,26 +265,26 @@ def test_dragon4_positional_interface_trim(self, tp):
265265
"1.2" if tp != np.float16 else "1.2002")
266266
assert_equal(fpos(tp('1.'), trim='-'), "1")
267267
assert_equal(fpos(tp('1.001'), precision=1, trim='-'), "1")
268-
268+
269269
@pytest.mark.parametrize("tp", available_float_dtypes)
270270
@pytest.mark.parametrize("pad_val", [10**5, np.iinfo("int32").max])
271271
def test_dragon4_positional_interface_overflow(self, tp, pad_val):
272272
# test is flaky for musllinux on np.float128
273273
if IS_MUSL and tp == np.float128:
274274
pytest.skip("Skipping flaky test of float128 on musllinux")
275-
275+
276276
fpos = np.format_float_positional
277277

278-
#gh-28068
279-
with pytest.raises(RuntimeError,
278+
#gh-28068
279+
with pytest.raises(RuntimeError,
280280
match="Float formatting result too large"):
281281
fpos(tp('1.047'), unique=False, precision=pad_val)
282282

283-
with pytest.raises(RuntimeError,
283+
with pytest.raises(RuntimeError,
284284
match="Float formatting result too large"):
285285
fpos(tp('1.047'), precision=2, pad_left=pad_val)
286286

287-
with pytest.raises(RuntimeError,
287+
with pytest.raises(RuntimeError,
288288
match="Float formatting result too large"):
289289
fpos(tp('1.047'), precision=2, pad_right=pad_val)
290290

@@ -293,7 +293,7 @@ def test_dragon4_scientific_interface(self, tp):
293293
# test is flaky for musllinux on np.float128
294294
if IS_MUSL and tp == np.float128:
295295
pytest.skip("Skipping flaky test of float128 on musllinux")
296-
296+
297297
fsci = np.format_float_scientific
298298

299299
# test exp_digits

numpy/_utils/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def decorator(func):
3232
func._module_file = sys.modules.get(func.__module__).__file__
3333
except (AttributeError, KeyError):
3434
pass
35-
35+
3636
func.__module__ = module
3737
return func
3838
return decorator

numpy/f2py/_src_pyf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def listrepl(mobj):
147147

148148
# convert all lists to named templates
149149
# new names are constructed as needed
150-
substr = list_re.sub(listrepl, substr)
150+
substr = list_re.sub(listrepl, substr)
151151

152152
numsubs = None
153153
base_rule = None

numpy/f2py/crackfortran.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1635,7 +1635,7 @@ def removespaces(expr):
16351635

16361636
def markinnerspaces(line):
16371637
"""
1638-
The function replace all spaces in the input variable line which are
1638+
The function replace all spaces in the input variable line which are
16391639
surrounded with quotation marks, with the triplet "@_@".
16401640
16411641
For instance, for the input "a 'b c'" the function returns "a 'b@_@c'"
@@ -1648,7 +1648,7 @@ def markinnerspaces(line):
16481648
-------
16491649
str
16501650
1651-
"""
1651+
"""
16521652
fragment = ''
16531653
inside = False
16541654
current_quote = None
@@ -2512,7 +2512,7 @@ def get_parameters(vars, global_params={}):
25122512
if not selected_kind_re.match(v):
25132513
v_ = v.split('_')
25142514
# In case there are additive parameters
2515-
if len(v_) > 1:
2515+
if len(v_) > 1:
25162516
v = ''.join(v_[:-1]).lower().replace(v_[-1].lower(), '')
25172517

25182518
# Currently this will not work for complex numbers.

numpy/f2py/tests/test_parameter.py

-1
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,3 @@ def test_constant_array_any_index(self):
127127
def test_constant_array_delims(self):
128128
x = self.module.foo_array_delims()
129129
assert x == 9
130-

numpy/lib/_format_impl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ def read_array(fp, allow_pickle=False, pickle_kwargs=None, *,
872872
data = _read_bytes(fp, read_size, "array data")
873873
array[i:i + read_count] = numpy.frombuffer(data, dtype=dtype,
874874
count=read_count)
875-
875+
876876
if array.size != count:
877877
raise ValueError(
878878
"Failed to read all data for array. "

numpy/lib/tests/test_format.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def test_file_truncated(tmp_path):
462462
f.truncate()
463463
with open(path, 'rb') as f:
464464
with pytest.raises(
465-
ValueError,
465+
ValueError,
466466
match = (
467467
r"EOF: reading array header, "
468468
r"expected (\d+) bytes got (\d+)"

numpy/lib/tests/test_function_base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2331,7 +2331,7 @@ def test_int_dtypes(self, dtype):
23312331
expected = sinc(x.astype(np.float64))
23322332
assert_allclose(actual, expected)
23332333
assert actual.dtype == np.float64
2334-
2334+
23352335
@pytest.mark.parametrize(
23362336
'dtype',
23372337
[np.float16, np.float32, np.longdouble, np.complex64, np.complex128]

numpy/ma/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6270,7 +6270,7 @@ def take(self, indices, axis=None, out=None, mode='raise'):
62706270
mask=[[False, False],
62716271
[ True, False]],
62726272
fill_value=999999)
6273-
"""
6273+
"""
62746274
(_data, _mask) = (self._data, self._mask)
62756275
cls = type(self)
62766276
# Make sure the indices are not masked

numpy/ma/tests/test_core.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1017,8 +1017,8 @@ def test_object_with_array(self):
10171017

10181018
def test_maskedarray_tofile_raises_notimplementederror(self):
10191019
xm = masked_array([1, 2, 3], mask=[False, True, False])
1020-
# Test case to check the NotImplementedError.
1021-
# It is not implemented at this point of time. We can change this in future
1020+
# Test case to check the NotImplementedError.
1021+
# It is not implemented at this point of time. We can change this in future
10221022
with temppath(suffix='.npy') as path:
10231023
with pytest.raises(NotImplementedError):
10241024
np.save(path, xm)

numpy/polynomial/_polybase.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ def has_samecoef(self, other):
200200
201201
"""
202202
return (
203-
len(self.coef) == len(other.coef)
204-
and np.all(self.coef == other.coef)
205-
)
203+
len(self.coef) == len(other.coef)
204+
and np.all(self.coef == other.coef)
205+
)
206206

207207
def has_samedomain(self, other):
208208
"""Check if domains match.

numpy/random/_examples/cffi/parse.py

-1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,3 @@ def parse_distributions_h(ffi, inc_dir):
5151
line = line.replace('RAND_INT_TYPE', 'int64_t')
5252
s.append(line)
5353
ffi.cdef('\n'.join(s))
54-

numpy/random/_examples/numba/extending.py

-2
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,3 @@ def bounded_uints(lb, ub, n, state):
8383

8484

8585
bounded_uints(323, 2394691, 10000000, ctypes_state.value)
86-
87-

numpy/tests/test_public_api.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,10 @@ def is_unexpected(name):
272272
"""Check if this needs to be considered."""
273273
return (
274274
'._' not in name and '.tests' not in name and '.setup' not in name
275-
and name not in PUBLIC_MODULES
276-
and name not in PUBLIC_ALIASED_MODULES
277-
and name not in PRIVATE_BUT_PRESENT_MODULES
278-
)
275+
and name not in PUBLIC_MODULES
276+
and name not in PUBLIC_ALIASED_MODULES
277+
and name not in PRIVATE_BUT_PRESENT_MODULES
278+
)
279279

280280

281281
if sys.version_info >= (3, 12):

ruff.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ extend-exclude = [
1616

1717
[lint]
1818
preview = true
19-
extend-select = [ "E" ]
19+
extend-select = [
20+
"E",
21+
"W",
22+
]
2023
ignore = [
2124
"F", # TODO: enable Pyflakes rules
2225
"E241",
@@ -30,9 +33,6 @@ ignore = [
3033
"E721",
3134
"E731",
3235
"E741",
33-
"W291",
34-
"W293",
35-
"W391",
3636
]
3737

3838
[lint.per-file-ignores]

0 commit comments

Comments
 (0)