Skip to content

Commit 6155ebc

Browse files
MAINT: apply ruff/pyupgrade rule UP034
UP034 Avoid extraneous parentheses
1 parent 3d54568 commit 6155ebc

File tree

16 files changed

+45
-45
lines changed

16 files changed

+45
-45
lines changed

benchmarks/benchmarks/bench_ufunc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
all_ufuncs = (getattr(np, name, None) for name in dir(np))
3333
all_ufuncs = set(filter(lambda f: isinstance(f, np.ufunc), all_ufuncs))
34-
bench_ufuncs = set((getattr(np, name, None) for name in ufuncs))
34+
bench_ufuncs = set(getattr(np, name, None) for name in ufuncs)
3535

3636
missing_ufuncs = all_ufuncs - bench_ufuncs
3737
if len(missing_ufuncs) > 0:
@@ -497,7 +497,7 @@ def time_floor_divide_int(self, dtype, size):
497497
class Scalar(Benchmark):
498498
def setup(self):
499499
self.x = np.asarray(1.0)
500-
self.y = np.asarray((1.0 + 1j))
500+
self.y = np.asarray(1.0 + 1j)
501501
self.z = complex(1.0, 1.0)
502502

503503
def time_add_scalar(self):

numpy/_core/tests/test_indexing.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ def _get_multi_index(self, arr, indices):
983983
elif indx is None:
984984
# this is like taking a slice with one element from a new axis:
985985
indices.append(['n', np.array([0], dtype=np.intp)])
986-
arr = arr.reshape((arr.shape[:ax] + (1,) + arr.shape[ax:]))
986+
arr = arr.reshape(arr.shape[:ax] + (1,) + arr.shape[ax:])
987987
continue
988988
if isinstance(indx, np.ndarray) and indx.dtype == bool:
989989
if indx.shape != arr.shape[ax:ax+indx.ndim]:
@@ -998,9 +998,9 @@ def _get_multi_index(self, arr, indices):
998998
flat_indx = np.array([0]*indx.sum(), dtype=np.intp)
999999
# concatenate axis into a single one:
10001000
if indx.ndim != 0:
1001-
arr = arr.reshape((arr.shape[:ax]
1001+
arr = arr.reshape(arr.shape[:ax]
10021002
+ (np.prod(arr.shape[ax:ax+indx.ndim]),)
1003-
+ arr.shape[ax+indx.ndim:]))
1003+
+ arr.shape[ax+indx.ndim:])
10041004
indx = flat_indx
10051005
else:
10061006
# This could be changed, a 0-d boolean index can
@@ -1067,9 +1067,9 @@ def _get_multi_index(self, arr, indices):
10671067
# First of all, reshape arr to combine fancy axes into one:
10681068
orig_shape = arr.shape
10691069
orig_slice = orig_shape[ax:ax + len(indx[1:])]
1070-
arr = arr.reshape((arr.shape[:ax]
1070+
arr = arr.reshape(arr.shape[:ax]
10711071
+ (np.prod(orig_slice).astype(int),)
1072-
+ arr.shape[ax + len(indx[1:]):]))
1072+
+ arr.shape[ax + len(indx[1:]):])
10731073

10741074
# Check if broadcasting works
10751075
res = np.broadcast(*indx[1:])
@@ -1103,9 +1103,9 @@ def _get_multi_index(self, arr, indices):
11031103
raise ValueError
11041104
arr = arr.take(mi.ravel(), axis=ax)
11051105
try:
1106-
arr = arr.reshape((arr.shape[:ax]
1106+
arr = arr.reshape(arr.shape[:ax]
11071107
+ mi.shape
1108-
+ arr.shape[ax+1:]))
1108+
+ arr.shape[ax+1:])
11091109
except ValueError:
11101110
# too many dimensions, probably
11111111
raise IndexError

numpy/_core/tests/test_multiarray.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6480,11 +6480,11 @@ def test_std_where(self):
64806480
[True],
64816481
[False]])
64826482
_cases = [
6483-
(0, True, 7.07106781*np.ones((5))),
6484-
(1, True, 1.41421356*np.ones((5))),
6483+
(0, True, 7.07106781*np.ones(5)),
6484+
(1, True, 1.41421356*np.ones(5)),
64856485
(0, whf,
64866486
np.array([4.0824829 , 8.16496581, 5., 7.39509973, 8.49836586])),
6487-
(0, whp, 2.5*np.ones((5)))
6487+
(0, whp, 2.5*np.ones(5))
64886488
]
64896489
for _ax, _wh, _res in _cases:
64906490
assert_allclose(a.std(axis=_ax, where=_wh), _res)

numpy/_core/tests/test_records.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ def test_recarray_from_obj(self):
114114

115115
mine = np.rec.fromarrays([a, b, c], names='date,data1,data2')
116116
for i in range(len(a)):
117-
assert_((mine.date[i] == list(range(1, 10))))
118-
assert_((mine.data1[i] == 0.0))
119-
assert_((mine.data2[i] == 0.0))
117+
assert_(mine.date[i] == list(range(1, 10)))
118+
assert_(mine.data1[i] == 0.0)
119+
assert_(mine.data2[i] == 0.0)
120120

121121
def test_recarray_repr(self):
122122
a = np.array([(1, 0.1), (2, 0.2)],

numpy/_core/tests/test_regression.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,8 +1071,8 @@ def test_astype_copy(self):
10711071
with open(filename, 'rb') as f:
10721072
xp = pickle.load(f, encoding='latin1')
10731073
xpd = xp.astype(np.float64)
1074-
assert_((xp.__array_interface__['data'][0] !=
1075-
xpd.__array_interface__['data'][0]))
1074+
assert_(xp.__array_interface__['data'][0] !=
1075+
xpd.__array_interface__['data'][0])
10761076

10771077
def test_compress_small_type(self):
10781078
# Ticket #789, changeset 5217.

numpy/_core/tests/test_shape_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def test_2D_array(self):
154154

155155
def test_generator(self):
156156
with pytest.raises(TypeError, match="arrays to stack must be"):
157-
hstack((np.arange(3) for _ in range(2)))
157+
hstack(np.arange(3) for _ in range(2))
158158
with pytest.raises(TypeError, match="arrays to stack must be"):
159159
hstack(map(lambda x: x, np.ones((3, 2))))
160160

@@ -209,7 +209,7 @@ def test_2D_array2(self):
209209

210210
def test_generator(self):
211211
with pytest.raises(TypeError, match="arrays to stack must be"):
212-
vstack((np.arange(3) for _ in range(2)))
212+
vstack(np.arange(3) for _ in range(2))
213213

214214
def test_casting_and_dtype(self):
215215
a = np.array([1, 2, 3])
@@ -477,7 +477,7 @@ def test_stack():
477477

478478
# do not accept generators
479479
with pytest.raises(TypeError, match="arrays to stack must be"):
480-
stack((x for x in range(3)))
480+
stack(x for x in range(3))
481481

482482
#casting and dtype test
483483
a = np.array([1, 2, 3])

numpy/_core/tests/test_stringdtype.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,12 @@ def test_self_casts(dtype, dtype2, strings):
232232
if hasattr(dtype, "na_object") and hasattr(dtype2, "na_object"):
233233
na1 = dtype.na_object
234234
na2 = dtype2.na_object
235-
if ((na1 is not na2 and
235+
if (na1 is not na2 and
236236
# check for pd_NA first because bool(pd_NA) is an error
237237
((na1 is pd_NA or na2 is pd_NA) or
238238
# the second check is a NaN check, spelled this way
239239
# to avoid errors from math.isnan and np.isnan
240-
(na1 != na2 and not (na1 != na1 and na2 != na2))))):
240+
(na1 != na2 and not (na1 != na1 and na2 != na2)))):
241241
with pytest.raises(TypeError):
242242
arr[:-1] == newarr[:-1]
243243
return

numpy/f2py/auxfuncs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,9 +701,9 @@ def getcallprotoargument(rout, cb_map={}):
701701
else:
702702
if not isattr_value(var):
703703
ctype = ctype + '*'
704-
if ((isstring(var)
704+
if (isstring(var)
705705
or isarrayofstrings(var) # obsolete?
706-
or isstringarray(var))):
706+
or isstringarray(var)):
707707
arg_types2.append('size_t')
708708
arg_types.append(ctype)
709709

numpy/f2py/crackfortran.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ def crackline(line, reset=0):
806806
raise Exception('crackline: groupcounter(=%s) is nonpositive. '
807807
'Check the blocks.'
808808
% (groupcounter))
809-
m1 = beginpattern[0].match((line))
809+
m1 = beginpattern[0].match(line)
810810
if (m1) and (not m1.group('this') == groupname[groupcounter]):
811811
raise Exception('crackline: End group %s does not match with '
812812
'previous Begin group %s\n\t%s' %
@@ -2735,8 +2735,8 @@ def analyzevars(block):
27352735
d = param_parse(d, params)
27362736
except (ValueError, IndexError, KeyError):
27372737
outmess(
2738-
('analyzevars: could not parse dimension for '
2739-
f'variable {d!r}\n')
2738+
'analyzevars: could not parse dimension for '
2739+
f'variable {d!r}\n'
27402740
)
27412741

27422742
dim_char = ':' if d == ':' else '*'
@@ -2816,9 +2816,9 @@ def compute_deps(v, deps):
28162816
compute_deps(v1, deps)
28172817
all_deps = set()
28182818
compute_deps(v, all_deps)
2819-
if ((v in n_deps
2819+
if (v in n_deps
28202820
or '=' in vars[v]
2821-
or 'depend' in vars[v])):
2821+
or 'depend' in vars[v]):
28222822
# Skip a variable that
28232823
# - n depends on
28242824
# - has user-defined initialization expression

numpy/f2py/symbolic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,9 +1084,9 @@ def as_factors(obj):
10841084
if coeff == 1:
10851085
return Expr(Op.FACTORS, {term: 1})
10861086
return Expr(Op.FACTORS, {term: 1, Expr.number(coeff): 1})
1087-
if ((obj.op is Op.APPLY
1087+
if (obj.op is Op.APPLY
10881088
and obj.data[0] is ArithOp.DIV
1089-
and not obj.data[2])):
1089+
and not obj.data[2]):
10901090
return Expr(Op.FACTORS, {obj.data[1][0]: 1, obj.data[1][1]: -1})
10911091
return Expr(Op.FACTORS, {obj: 1})
10921092
raise OpError(f'cannot convert {type(obj)} to terms Expr')

0 commit comments

Comments
 (0)