Skip to content

Commit 7736d4b

Browse files
authored
STY: Enable some passing rules (#57200)
* Enable B006 * Enable B011 * Enable B019 * Enable B020 * Enable B020 * Enable PYI and othe rule * Enable PLC1901 * Use values instead of items * Use union * Ignore one case
1 parent 680b215 commit 7736d4b

File tree

13 files changed

+44
-54
lines changed

13 files changed

+44
-54
lines changed

pandas/_libs/tslibs/vectorized.pyi

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
"""
2-
For cython types that cannot be represented precisely, closest-available
3-
python equivalents are used, and the precise types kept as adjacent comments.
4-
"""
1+
# For cython types that cannot be represented precisely, closest-available
2+
# python equivalents are used, and the precise types kept as adjacent comments.
53
from datetime import tzinfo
64

75
import numpy as np

pandas/core/indexers/objects.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def get_window_bounds(
399399
start_arrays = []
400400
end_arrays = []
401401
window_indices_start = 0
402-
for key, indices in self.groupby_indices.items():
402+
for indices in self.groupby_indices.values():
403403
index_array: np.ndarray | None
404404

405405
if self.index_array is not None:

pandas/io/formats/style_render.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1996,7 +1996,7 @@ class Tooltips:
19961996

19971997
def __init__(
19981998
self,
1999-
css_props: CSSProperties = [
1999+
css_props: CSSProperties = [ # noqa: B006
20002000
("visibility", "hidden"),
20012001
("position", "absolute"),
20022002
("z-index", 1),

pandas/io/json/_normalize.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,8 @@ def _recursive_extract(data, path, seen_meta, level: int = 0) -> None:
537537
if values.ndim > 1:
538538
# GH 37782
539539
values = np.empty((len(v),), dtype=object)
540-
for i, v in enumerate(v):
541-
values[i] = v
540+
for i, val in enumerate(v):
541+
values[i] = val
542542

543543
result[k] = values.repeat(lengths)
544544
return result

pandas/tests/arrays/masked/test_arithmetic.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ def test_array_scalar_like_equivalence(data, all_arithmetic_operators):
5555
scalar_array = pd.array([scalar] * len(data), dtype=data.dtype)
5656

5757
# TODO also add len-1 array (np.array([scalar], dtype=data.dtype.numpy_dtype))
58-
for scalar in [scalar, data.dtype.type(scalar)]:
58+
for val in [scalar, data.dtype.type(scalar)]:
5959
if is_bool_not_implemented(data, all_arithmetic_operators):
6060
msg = "operator '.*' not implemented for bool dtypes"
6161
with pytest.raises(NotImplementedError, match=msg):
62-
op(data, scalar)
62+
op(data, val)
6363
with pytest.raises(NotImplementedError, match=msg):
6464
op(data, scalar_array)
6565
else:
66-
result = op(data, scalar)
66+
result = op(data, val)
6767
expected = op(data, scalar_array)
6868
tm.assert_extension_array_equal(result, expected)
6969

@@ -214,13 +214,13 @@ def test_error_len_mismatch(data, all_arithmetic_operators):
214214
msg = "operator '.*' not implemented for bool dtypes"
215215
err = NotImplementedError
216216

217-
for other in [other, np.array(other)]:
217+
for val in [other, np.array(other)]:
218218
with pytest.raises(err, match=msg):
219-
op(data, other)
219+
op(data, val)
220220

221221
s = pd.Series(data)
222222
with pytest.raises(err, match=msg):
223-
op(s, other)
223+
op(s, val)
224224

225225

226226
@pytest.mark.parametrize("op", ["__neg__", "__abs__", "__invert__"])

pandas/tests/copy_view/index/test_index.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pandas.tests.copy_view.util import get_array
1111

1212

13-
def index_view(index_data=[1, 2]):
13+
def index_view(index_data):
1414
df = DataFrame({"a": index_data, "b": 1.5})
1515
view = df[:]
1616
df = df.set_index("a", drop=True)
@@ -142,7 +142,7 @@ def test_index_from_index(using_copy_on_write, warn_copy_on_write):
142142
],
143143
)
144144
def test_index_ops(using_copy_on_write, func, request):
145-
idx, view_ = index_view()
145+
idx, view_ = index_view([1, 2])
146146
expected = idx.copy(deep=True)
147147
if "astype" in request.node.callspec.id:
148148
expected = expected.astype("Int64")

pandas/tests/frame/test_query_eval.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -949,8 +949,8 @@ def test_str_query_method(self, parser, engine):
949949
ops = 2 * ([eq] + [ne])
950950
msg = r"'(Not)?In' nodes are not implemented"
951951

952-
for lhs, op, rhs in zip(lhs, ops, rhs):
953-
ex = f"{lhs} {op} {rhs}"
952+
for lh, op_, rh in zip(lhs, ops, rhs):
953+
ex = f"{lh} {op_} {rh}"
954954
with pytest.raises(NotImplementedError, match=msg):
955955
df.query(
956956
ex,
@@ -990,8 +990,8 @@ def test_str_list_query_method(self, parser, engine):
990990
ops = 2 * ([eq] + [ne])
991991
msg = r"'(Not)?In' nodes are not implemented"
992992

993-
for lhs, op, rhs in zip(lhs, ops, rhs):
994-
ex = f"{lhs} {op} {rhs}"
993+
for lh, ops_, rh in zip(lhs, ops, rhs):
994+
ex = f"{lh} {ops_} {rh}"
995995
with pytest.raises(NotImplementedError, match=msg):
996996
df.query(ex, engine=engine, parser=parser)
997997
else:

pandas/tests/io/test_feather.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ def check_external_error_on_write(self, df):
3636
with tm.ensure_clean() as path:
3737
to_feather(df, path)
3838

39-
def check_round_trip(self, df, expected=None, write_kwargs={}, **read_kwargs):
39+
def check_round_trip(self, df, expected=None, write_kwargs=None, **read_kwargs):
40+
if write_kwargs is None:
41+
write_kwargs = {}
4042
if expected is None:
4143
expected = df.copy()
4244

pandas/tests/plotting/common.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ def _check_box_return_type(
433433
raise AssertionError
434434

435435

436-
def _check_grid_settings(obj, kinds, kws={}):
436+
def _check_grid_settings(obj, kinds, kws=None):
437437
# Make sure plot defaults to rcParams['axes.grid'] setting, GH 9792
438438

439439
import matplotlib as mpl
@@ -446,6 +446,8 @@ def is_grid_on():
446446

447447
return not (xoff and yoff)
448448

449+
if kws is None:
450+
kws = {}
449451
spndx = 1
450452
for kind in kinds:
451453
mpl.pyplot.subplot(1, 4 * len(kinds), spndx)

pandas/tests/reshape/test_pivot.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -890,10 +890,14 @@ def _check_output(
890890
result,
891891
values_col,
892892
data,
893-
index=["A", "B"],
894-
columns=["C"],
893+
index=None,
894+
columns=None,
895895
margins_col="All",
896896
):
897+
if index is None:
898+
index = ["A", "B"]
899+
if columns is None:
900+
columns = ["C"]
897901
col_margins = result.loc[result.index[:-1], margins_col]
898902
expected_col_margins = data.groupby(index)[values_col].mean()
899903
tm.assert_series_equal(col_margins, expected_col_margins, check_names=False)

pandas/tests/window/test_expanding.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ def test_expanding_count_with_min_periods_exceeding_series_length(frame_or_serie
178178
def test_iter_expanding_dataframe(df, expected, min_periods):
179179
# GH 11704
180180
df = DataFrame(df)
181-
expected = [DataFrame(values, index=index) for (values, index) in expected]
181+
expecteds = [DataFrame(values, index=index) for (values, index) in expected]
182182

183-
for expected, actual in zip(expected, df.expanding(min_periods)):
183+
for expected, actual in zip(expecteds, df.expanding(min_periods)):
184184
tm.assert_frame_equal(actual, expected)
185185

186186

@@ -197,9 +197,9 @@ def test_iter_expanding_dataframe(df, expected, min_periods):
197197
)
198198
def test_iter_expanding_series(ser, expected, min_periods):
199199
# GH 11704
200-
expected = [Series(values, index=index) for (values, index) in expected]
200+
expecteds = [Series(values, index=index) for (values, index) in expected]
201201

202-
for expected, actual in zip(expected, ser.expanding(min_periods)):
202+
for expected, actual in zip(expecteds, ser.expanding(min_periods)):
203203
tm.assert_series_equal(actual, expected)
204204

205205

pandas/tests/window/test_rolling.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,9 @@ def test_rolling_count_default_min_periods_with_null_values(frame_or_series):
760760
def test_iter_rolling_dataframe(df, expected, window, min_periods):
761761
# GH 11704
762762
df = DataFrame(df)
763-
expected = [DataFrame(values, index=index) for (values, index) in expected]
763+
expecteds = [DataFrame(values, index=index) for (values, index) in expected]
764764

765-
for expected, actual in zip(expected, df.rolling(window, min_periods=min_periods)):
765+
for expected, actual in zip(expecteds, df.rolling(window, min_periods=min_periods)):
766766
tm.assert_frame_equal(actual, expected)
767767

768768

@@ -805,10 +805,10 @@ def test_iter_rolling_on_dataframe(expected, window):
805805
}
806806
)
807807

808-
expected = [
808+
expecteds = [
809809
DataFrame(values, index=df.loc[index, "C"]) for (values, index) in expected
810810
]
811-
for expected, actual in zip(expected, df.rolling(window, on="C")):
811+
for expected, actual in zip(expecteds, df.rolling(window, on="C")):
812812
tm.assert_frame_equal(actual, expected)
813813

814814

@@ -856,9 +856,11 @@ def test_iter_rolling_on_dataframe_unordered():
856856
)
857857
def test_iter_rolling_series(ser, expected, window, min_periods):
858858
# GH 11704
859-
expected = [Series(values, index=index) for (values, index) in expected]
859+
expecteds = [Series(values, index=index) for (values, index) in expected]
860860

861-
for expected, actual in zip(expected, ser.rolling(window, min_periods=min_periods)):
861+
for expected, actual in zip(
862+
expecteds, ser.rolling(window, min_periods=min_periods)
863+
):
862864
tm.assert_series_equal(actual, expected)
863865

864866

@@ -904,11 +906,11 @@ def test_iter_rolling_datetime(expected, expected_index, window):
904906
# GH 11704
905907
ser = Series(range(5), index=date_range(start="2020-01-01", periods=5, freq="D"))
906908

907-
expected = [
909+
expecteds = [
908910
Series(values, index=idx) for (values, idx) in zip(expected, expected_index)
909911
]
910912

911-
for expected, actual in zip(expected, ser.rolling(window)):
913+
for expected, actual in zip(expecteds, ser.rolling(window)):
912914
tm.assert_series_equal(actual, expected)
913915

914916

pyproject.toml

-18
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,6 @@ ignore = [
245245
"E402",
246246
# do not assign a lambda expression, use a def
247247
"E731",
248-
# line break before binary operator
249-
# "W503", # not yet implemented
250-
# line break after binary operator
251-
# "W504", # not yet implemented
252-
# controversial
253-
"B006",
254248
# controversial
255249
"B007",
256250
# controversial
@@ -259,18 +253,10 @@ ignore = [
259253
"B009",
260254
# getattr is used to side-step mypy
261255
"B010",
262-
# tests use assert False
263-
"B011",
264256
# tests use comparisons but not their returned value
265257
"B015",
266-
# false positives
267-
"B019",
268-
# Loop control variable overrides iterable it iterates
269-
"B020",
270258
# Function definition does not bind loop variable
271259
"B023",
272-
# Functions defined inside a loop must not use variables redefined in the loop
273-
# "B301", # not yet implemented
274260
# Only works with python >=3.10
275261
"B905",
276262
# Too many arguments to function call
@@ -285,14 +271,10 @@ ignore = [
285271
"PLW2901",
286272
# Global statements are discouraged
287273
"PLW0603",
288-
# Docstrings should not be included in stubs
289-
"PYI021",
290274
# Use `typing.NamedTuple` instead of `collections.namedtuple`
291275
"PYI024",
292276
# No builtin `eval()` allowed
293277
"PGH001",
294-
# compare-to-empty-string
295-
"PLC1901",
296278
# while int | float can be shortened to float, the former is more explicit
297279
"PYI041",
298280
# incorrect-dict-iterator, flags valid Series.items usage

0 commit comments

Comments
 (0)