8000 MNT: Apply assorted ruff/Pylint Warning rules (PLW) by DimitriPapadopoulos · Pull Request #28756 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MNT: Apply assorted ruff/Pylint Warning rules (PLW) #28756

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 4 commits into from
Apr 18, 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
STY: Apply ruff/Pylint rule PLW0108
Lambda may be unnecessary; consider inlining inner function
  • Loading branch information
DimitriPapadopoulos committed Apr 18, 2025
commit 4233c813f5d652096297f66ad04fd03ee60810ce
4 changes: 2 additions & 2 deletions numpy/_core/tests/test_arrayprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ def _format_function(x):
"[. o O]")
assert_(np.array2string(x, formatter={'all': lambda x: "%.4f" % x}) ==
"[0.0000 1.0000 2.0000]")
assert_equal(np.array2string(x, formatter={'int': lambda x: hex(x)}),
assert_equal(np.array2string(x, formatter={'int': hex}),
x_hex)
assert_equal(np.array2string(x, formatter={'int': lambda x: oct(x)}),
assert_equal(np.array2string(x, formatter={'int': oct}),
x_oct)

x = np.arange(3.)
Expand Down
4 changes: 2 additions & 2 deletions numpy/_core/tests/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class TestCtypesGetter(_DeprecationTestCase):
)
def test_deprecated(self, name: str) -> None:
func = getattr(self.ctypes, name)
self.assert_deprecated(lambda: func())
self.assert_deprecated(func)

@pytest.mark.parametrize(
"name", ["data", "shape", "strides", "_as_parameter_"]
Expand Down Expand Up @@ -361,7 +361,7 @@ def test_lib_functions_deprecation_call(self):
self.assert_deprecated(lambda: recfromtxt(data_gen(), **kwargs))

self.assert_deprecated(lambda: disp("test"))
self.assert_deprecated(lambda: get_array_wrap())
self.assert_deprecated(get_array_wrap)
self.assert_deprecated(lambda: maximum_sctype(int))

self.assert_deprecated(lambda: in1d([1], [1]))
Expand Down
4 changes: 2 additions & 2 deletions numpy/_core/tests/test_multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3743,8 +3743,8 @@ def test_conjugate(self):
assert_equal(ac, np.conjugate(a))

a = np.array([1 - 1j, 1, 2.0, 'f'], object)
assert_raises(TypeError, lambda: a.conj())
assert_raises(TypeError, lambda: a.conjugate())
assert_raises(TypeError, a.conj)
assert_raises(TypeError, a.conjugate)

def test_conjugate_out(self):
# Minimal test for the out argument being passed on correctly
Expand Down
2 changes: 1 addition & 1 deletion numpy/f2py/tests/test_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def check_function(self, name):
assert r == 6
r = t(lambda a: 5 + a, fun_extra_args=(7, ))
assert r == 12
r = t(lambda a: math.degrees(a), fun_extra_args=(math.pi, ))
r = t(math.degrees, fun_extra_args=(math.pi, ))
assert r == 180
r = t(math.degrees, fun_extra_args=(math.pi, ))
assert r == 180
Expand Down
5 changes: 2 additions & 3 deletions numpy/lib/_function_base_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
# --- HYNDMAN and FAN METHODS
# Discrete methods
'inverted_cdf': {
'get_virtual_index': lambda n, quantiles: _inverted_cdf(n, quantiles),
'get_virtual_index': _inverted_cdf,
'fix_gamma': None, # should never be called
},
'averaged_inverted_cdf': {
Expand All @@ -79,8 +79,7 @@
where=gamma == 0),
},
'closest_observation': {
'get_virtual_index': lambda n, quantiles: _closest_observation(n,
quantiles),
'get_virtual_index': _closest_observation,
'fix_gamma': None, # should never be called
},
# Continuous methods
Expand Down
2 changes: 1 addition & 1 deletion numpy/lib/tests/test_function_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3057,7 +3057,7 @@ def test_non_finite_behavior_exact_x(self):
assert_almost_equal(np.interp(x, xp, fp), [1, 2, np.nan, np.nan, 4])

@pytest.fixture(params=[
lambda x: np.float64(x),
np.float64,
lambda x: _make_complex(x, 0),
lambda x: _make_complex(0, x),
lambda x: _make_complex(x, np.multiply(x, -2))
Expand Down
2 changes: 1 addition & 1 deletion numpy/testing/_private/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ def rundocs(filename=None, raise_on_error=True):

msg = []
if raise_on_error:
out = lambda s: msg.append(s)
out = msg.append
else:
out = None

Expand Down
0