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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 6 additions & 2 deletions
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)

0 commit comments

Comments
 (0)