Skip to content

Commit a2d5564

Browse files
authored
Fix code triggering superfluous-parens pylint messages (#49219)
* Fix code triggering superfluous-parens pylint messages * Add previously removed asserts to tests * Refactor CustomClass test to avoid using >=
1 parent ebf0a7a commit a2d5564

File tree

14 files changed

+22
-25
lines changed

14 files changed

+22
-25
lines changed

pandas/core/computation/pytables.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ def visit_Attribute(self, node, **kwargs):
470470
# try to get the value to see if we are another expression
471471
try:
472472
resolved = resolved.value
473-
except (AttributeError):
473+
except AttributeError:
474474
pass
475475

476476
try:

pandas/io/formats/style.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1723,7 +1723,7 @@ def _apply(
17231723
f"Function {repr(func)} must return a DataFrame or ndarray "
17241724
f"when passed to `Styler.apply` with axis=None"
17251725
)
1726-
if not (data.shape == result.shape):
1726+
if data.shape != result.shape:
17271727
raise ValueError(
17281728
f"Function {repr(func)} returned ndarray with wrong shape.\n"
17291729
f"Result has shape: {result.shape}\n"
@@ -3310,9 +3310,9 @@ def bar(
33103310
"(eg: color=['#d65f5f', '#5fba7d'])"
33113311
)
33123312

3313-
if not (0 <= width <= 100):
3313+
if not 0 <= width <= 100:
33143314
raise ValueError(f"`width` must be a value in [0, 100], got {width}")
3315-
elif not (0 <= height <= 100):
3315+
elif not 0 <= height <= 100:
33163316
raise ValueError(f"`height` must be a value in [0, 100], got {height}")
33173317

33183318
if subset is None:

pandas/io/pytables.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4945,7 +4945,7 @@ def _unconvert_index(data, kind: str, encoding: str, errors: str) -> np.ndarray
49454945
elif kind == "date":
49464946
try:
49474947
index = np.asarray([date.fromordinal(v) for v in data], dtype=object)
4948-
except (ValueError):
4948+
except ValueError:
49494949
index = np.asarray([date.fromtimestamp(v) for v in data], dtype=object)
49504950
elif kind in ("integer", "float", "bool"):
49514951
index = np.asarray(data)

pandas/tests/groupby/test_allowlist.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ def test_all_methods_categorized(mframe):
292292
new_names -= transformation_kernels
293293
new_names -= groupby_other_methods
294294

295-
assert not (reduction_kernels & transformation_kernels)
296-
assert not (reduction_kernels & groupby_other_methods)
297-
assert not (transformation_kernels & groupby_other_methods)
295+
assert not reduction_kernels & transformation_kernels
296+
assert not reduction_kernels & groupby_other_methods
297+
assert not transformation_kernels & groupby_other_methods
298298

299299
# new public method?
300300
if new_names:
@@ -318,7 +318,7 @@ def test_all_methods_categorized(mframe):
318318
all_categorized = reduction_kernels | transformation_kernels | groupby_other_methods
319319
print(names)
320320
print(all_categorized)
321-
if not (names == all_categorized):
321+
if names != all_categorized:
322322
msg = f"""
323323
Some methods which are supposed to be on the Grouper class
324324
are missing:

pandas/tests/indexes/datetimelike.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_str(self, simple_index):
4949
# test the string repr
5050
idx = simple_index
5151
idx.name = "foo"
52-
assert not (f"length={len(idx)}" in str(idx))
52+
assert f"length={len(idx)}" not in str(idx)
5353
assert "'foo'" in str(idx)
5454
assert type(idx).__name__ in str(idx)
5555

pandas/tests/indexes/timedeltas/test_indexing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def test_contains(self):
374374
# GH#13603
375375
td = to_timedelta(range(5), unit="d") + offsets.Hour(1)
376376
for v in [NaT, None, float("nan"), np.nan]:
377-
assert not (v in td)
377+
assert v not in td
378378

379379
td = to_timedelta([NaT])
380380
for v in [NaT, None, float("nan"), np.nan]:

pandas/tests/io/formats/style/test_style.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def test_clear(mi_styler_comp):
352352

353353
# test vars have same vales on obj and clean copy after clearing
354354
styler.clear()
355-
for attr in [a for a in styler.__dict__ if not (callable(a))]:
355+
for attr in [a for a in styler.__dict__ if not callable(a)]:
356356
res = getattr(styler, attr) == getattr(clean_copy, attr)
357357
assert all(res) if hasattr(res, "__iter__") else res
358358

pandas/tests/io/formats/test_format.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ def test_to_string_truncate_indices(self, index, h, w):
985985
if w == 20:
986986
assert has_horizontally_truncated_repr(df)
987987
else:
988-
assert not (has_horizontally_truncated_repr(df))
988+
assert not has_horizontally_truncated_repr(df)
989989
with option_context("display.max_rows", 15, "display.max_columns", 15):
990990
if h == 20 and w == 20:
991991
assert has_doubly_truncated_repr(df)

pandas/tests/io/generate_legacy_storage_files.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def write_legacy_file():
326326
# force our cwd to be the first searched
327327
sys.path.insert(0, ".")
328328

329-
if not (3 <= len(sys.argv) <= 4):
329+
if not 3 <= len(sys.argv) <= 4:
330330
exit(
331331
"Specify output directory and storage type: generate_legacy_"
332332
"storage_files.py <output_dir> <storage_type> "

pandas/tests/scalar/timedelta/test_arithmetic.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1055,13 +1055,13 @@ def __gt__(self, other):
10551055

10561056
t = Timedelta("1s")
10571057

1058-
assert not (t == "string")
1059-
assert not (t == 1)
1060-
assert not (t == CustomClass())
1061-
assert not (t == CustomClass(cmp_result=False))
1058+
assert t != "string"
1059+
assert t != 1
1060+
assert t != CustomClass()
1061+
assert t != CustomClass(cmp_result=False)
10621062

10631063
assert t < CustomClass(cmp_result=True)
1064-
assert not (t < CustomClass(cmp_result=False))
1064+
assert not t < CustomClass(cmp_result=False)
10651065

10661066
assert t == CustomClass(cmp_result=True)
10671067

pandas/tests/scalar/timestamp/test_comparisons.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,5 +324,5 @@ def __eq__(self, other) -> bool:
324324
for left, right in [(inf, timestamp), (timestamp, inf)]:
325325
assert left > right or left < right
326326
assert left >= right or left <= right
327-
assert not (left == right)
327+
assert not left == right
328328
assert left != right

pandas/tests/series/methods/test_reindex.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_reindex(datetime_series, string_series):
5555

5656
# return a copy the same index here
5757
result = datetime_series.reindex()
58-
assert not (result is datetime_series)
58+
assert result is not datetime_series
5959

6060

6161
def test_reindex_nan():

pandas/tests/tseries/offsets/test_ticks.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,10 @@ def test_tick_equality(cls, n, m):
9090
left = cls(n)
9191
right = cls(m)
9292
assert left != right
93-
assert not (left == right)
9493

9594
right = cls(n)
9695
assert left == right
97-
assert not (left != right)
96+
assert not left != right
9897

9998
if n != 0:
10099
assert cls(n) != cls(-n)

pyproject.toml

-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ disable = [
8989
"missing-function-docstring",
9090
"missing-module-docstring",
9191
"singleton-comparison",
92-
"superfluous-parens",
9392
"too-many-lines",
9493
"typevar-name-incorrect-variance",
9594
"ungrouped-imports",
@@ -135,7 +134,6 @@ disable = [
135134
"too-many-branches",
136135
"too-many-instance-attributes",
137136
"too-many-locals",
138-
"too-many-locals",
139137
"too-many-nested-blocks",
140138
"too-many-public-methods",
141139
"too-many-return-statements",

0 commit comments

Comments
 (0)