Skip to content

MAINT: Enable linting with ruff E501 #29300

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

Merged
merged 3 commits into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
MAINT: Enforce ruff E501
  • Loading branch information
eendebakpt committed Jul 1, 2025
commit 2e3c77ab6ac5ad110fa54552026feb7f60ebcbd0
6 changes: 4 additions & 2 deletions numpy/_core/tests/test_simd_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
int_sfx = unsigned_sfx + signed_sfx
all_sfx = unsigned_sfx + int_sfx

@pytest.mark.skipif(not npyv, reason="could not find any SIMD extension with NPYV support")
@pytest.mark.skipif(not npyv,
reason="could not find any SIMD extension with NPYV support")
class Test_SIMD_MODULE:

@pytest.mark.parametrize('sfx', all_sfx)
Expand All @@ -47,7 +48,8 @@ def test_raises(self):
pytest.raises(TypeError, vcb("setall"), [1])
pytest.raises(TypeError, vcb("load"), 1)
pytest.raises(ValueError, vcb("load"), [1])
pytest.raises(ValueError, vcb("store"), [1], getattr(npyv, f"reinterpret_{sfx}_u32")(a))
reinterpret = getattr(npyv, f"reinterpret_{sfx}_u32")(a)
pytest.raises(ValueError, vcb("store"), [1], reinterpret)

@pytest.mark.skipif(not npyv2, reason=(
"could not find a second SIMD extension with NPYV support"
Expand Down
13 changes: 6 additions & 7 deletions numpy/_core/tests/test_ufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,17 +1100,15 @@ def test_output_ellipsis_errors(self):
match=r"out=\.\.\. is only allowed as a keyword argument."):
np.add.reduce(1, (), None, ...)

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

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

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

def test_axes_argument(self):
Expand Down Expand Up @@ -1556,7 +1554,8 @@ def __eq__(self, other):

arr1d = np.array([HasComparisons()])
assert_equal(arr1d == arr1d, np.array([True]))
assert_equal(np.equal(arr1d, arr1d), np.array([True])) # normal behavior is a cast
# normal behavior is a cast
assert_equal(np.equal(arr1d, arr1d), np.array([True]))
assert_equal(np.equal(arr1d, arr1d, dtype=object), np.array(['==']))

def test_object_array_reduction(self):
Expand Down
12 changes: 10 additions & 2 deletions numpy/_core/tests/test_umath_accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,16 @@ def test_validate_transcendentals(self):
npfunc = getattr(np, npname)
for datatype in np.unique(data['type']):
data_subset = data[data['type'] == datatype]
inval = np.array(str_to_float(data_subset['input'].astype(str), data_subset['type'].astype(str)), dtype=eval(datatype))
outval = np.array(str_to_float(data_subset['output'].astype(str), data_subset['type'].astype(str)), dtype=eval(datatype))
data_input_str = data_subset['input'].astype(str)
data_output_str = data_subset['output'].astype(str)
data_type_str = data_subset['type'].astype(str)

inval = np.array(str_to_float(data_input_str,
data_type_str),
dtype=eval(datatype))
outval = np.array(str_to_float(data_output_str,
data_type_str),
dtype=eval(datatype))
perm = np.random.permutation(len(inval))
inval = inval[perm]
outval = outval[perm]
Expand Down
44 changes: 24 additions & 20 deletions numpy/_core/tests/test_umath_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,31 +562,35 @@ class TestSpecialComplexAVX:
@pytest.mark.parametrize("stride", [-4, -2, -1, 1, 2, 4])
@pytest.mark.parametrize("astype", [np.complex64, np.complex128])
def test_array(self, stride, astype):
arr = np.array([complex(np.nan, np.nan),
complex(np.nan, np.inf),
complex(np.inf, np.nan),
complex(np.inf, np.inf),
complex(0., np.inf),
complex(np.inf, 0.),
complex(0., 0.),
complex(0., np.nan),
complex(np.nan, 0.)], dtype=astype)
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)
sq_true = np.array([complex(np.nan, np.nan),
complex(np.nan, np.nan),
complex(np.nan, np.nan),
complex(np.nan, np.inf),
complex(-np.inf, np.nan),
complex(np.inf, np.nan),
complex(0., 0.),
complex(np.nan, np.nan),
complex(np.nan, np.nan)], dtype=astype)
nan = np.nan
inf = np.inf
arr = np.array([complex(nan, nan),
complex(nan, inf),
complex(inf, nan),
complex(inf, inf),
complex(0., inf),
complex(inf, 0.),
complex(0., 0.),
complex(0., nan),
complex(nan, 0.)], dtype=astype)
abs_true = np.array([nan, inf, inf, inf, inf, inf, 0., nan, nan],
dtype=arr.real.dtype)
sq_true = np.array([complex(nan, nan),
complex(nan, nan),
complex(nan, nan),
complex(nan, inf),
complex(-inf, nan),
complex(inf, nan),
complex(0., 0.),
complex(nan, nan),
complex(nan, nan)], dtype=astype)
with np.errstate(invalid='ignore'):
assert_equal(np.abs(arr[::stride]), abs_true[::stride])
assert_equal(np.square(arr[::stride]), sq_true[::stride])

class TestComplexAbsoluteAVX:
@pytest.mark.parametrize("arraysize", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 18, 19])
@pytest.mark.parametrize("arraysize",
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 18, 19])
@pytest.mark.parametrize("stride", [-4, -3, -2, -1, 1, 2, 3, 4])
@pytest.mark.parametrize("astype", [np.complex64, np.complex128])
# test to ensure masking and strides work as intended in the AVX implementation
Expand Down
12 changes: 8 additions & 4 deletions numpy/tests/test_configtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
PKG_CONFIG_DIR = NUMPY_ROOT / '_core' / 'lib' / 'pkgconfig'


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


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


@pytest.mark.skipif(not IS_INSTALLED, reason="numpy.pc is only available when numpy is installed")
@pytest.mark.skipif(not IS_INSTALLED,
reason="numpy.pc is only available when numpy is installed")
@pytest.mark.skipif(IS_EDITABLE, reason="editable installs don't have a numpy.pc")
def test_pkg_config_config_exists():
assert PKG_CONFIG_DIR.joinpath('numpy.pc').is_file()
8 changes: 3 additions & 5 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,20 @@ ignore = [
"numpy/_core/tests/test_multiarray.py" = ["E501"]
"numpy/_core/tests/test_multithreading.py" = ["E501"]
"numpy/_core/tests/test_nditer*py" = ["E501"]
"numpy/_core/tests/test_ufunc*py" = ["E501"]
"numpy/_core/tests/test_umath*py" = ["E501"]
"numpy/_core/tests/test_umath.py" = ["E501"]
"numpy/_core/tests/test_numeric*.py" = ["E501"]
"numpy/_core/tests/test_regression.py" = ["E501"]
"numpy/_core/tests/test_shape_base.py" = ["E501"]
"numpy/_core/tests/test_simd*.py" = ["E501"]
"numpy/_core/tests/test_simd.py" = ["E501"]
"numpy/_core/tests/test_strings.py" = ["E501"]
"numpy/_core/_add_newdocs.py" = ["E501"]
"numpy/_core/_add_newdocs_scalars.py" = ["E501"]
"numpy/_core/code_generators/generate_umath.py" = ["E501"]
"numpy/lib/tests/test_function_base.py" = ["E501"]
"numpy/lib/tests/test_format.py" = ["E501"]
"numpy/lib/tests/test_io.py" = ["E501"]
"numpy/lib/tests/test_polynomial.py" = ["E501"]
#"numpy/lib/tests/test_polynomial.py" = ["E501"]
"numpy/linalg/tests/test_linalg.py" = ["E501"]
"numpy/tests/test_configtool.py" = ["E501"]
"numpy/f2py/*py" = ["E501"]
# for typing related files we follow https://typing.python.org/en/latest/guides/writing_stubs.html#maximum-line-length
"numpy/_typing/_array_like.py" = ["E501"]
Expand Down
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