Skip to content

Commit cdab83e

Browse files
tqa236mroeschke
authored andcommitted
Migrate pylint to ruff (pandas-dev#57182)
Configure ruff pylint Co-authored-by: Matthew Roeschke <[email protected]>
1 parent 059c23d commit cdab83e

File tree

28 files changed

+80
-259
lines changed

28 files changed

+80
-259
lines changed

.github/workflows/code-checks.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
echo "PYTHONPATH=$PYTHONPATH" >> $GITHUB_ENV
8686
if: ${{ steps.build.outcome == 'success' && always() }}
8787

88-
- name: Typing + pylint
88+
- name: Typing
8989
uses: pre-commit/[email protected]
9090
with:
9191
extra_args: --verbose --hook-stage manual --all-files

.pre-commit-config.yaml

+1-20
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ci:
1616
autofix_prs: false
1717
autoupdate_schedule: monthly
1818
# manual stage hooks
19-
skip: [pylint, pyright, mypy]
19+
skip: [pyright, mypy]
2020
repos:
2121
- repo: https://github.com/astral-sh/ruff-pre-commit
2222
rev: v0.3.4
@@ -67,25 +67,6 @@ repos:
6767
- id: fix-encoding-pragma
6868
args: [--remove]
6969
- id: trailing-whitespace
70-
- repo: https://github.com/pylint-dev/pylint
71-
rev: v3.0.1
72-
hooks:
73-
- id: pylint
74-
stages: [manual]
75-
args: [--load-plugins=pylint.extensions.redefined_loop_name, --fail-on=I0021]
76-
- id: pylint
77-
alias: redefined-outer-name
78-
name: Redefining name from outer scope
79-
files: ^pandas/
80-
exclude: |
81-
(?x)
82-
^pandas/tests # keep excluded
83-
|/_testing/ # keep excluded
84-
|^pandas/util/_test_decorators\.py # keep excluded
85-
|^pandas/_version\.py # keep excluded
86-
|^pandas/conftest\.py # keep excluded
87-
args: [--disable=all, --enable=redefined-outer-name]
88-
stages: [manual]
8970
- repo: https://github.com/PyCQA/isort
9071
rev: 5.13.2
9172
hooks:

pandas/_libs/tslibs/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"is_supported_dtype",
3737
]
3838

39-
from pandas._libs.tslibs import dtypes # pylint: disable=import-self
39+
from pandas._libs.tslibs import dtypes
4040
from pandas._libs.tslibs.conversion import localize_pydatetime
4141
from pandas._libs.tslibs.dtypes import (
4242
Resolution,

pandas/core/arrays/categorical.py

-1
Original file line numberDiff line numberDiff line change
@@ -2482,7 +2482,6 @@ def unique(self) -> Self:
24822482
['b', 'a']
24832483
Categories (3, object): ['a' < 'b' < 'c']
24842484
"""
2485-
# pylint: disable=useless-parent-delegation
24862485
return super().unique()
24872486

24882487
def _cast_quantile_result(self, res_values: np.ndarray) -> np.ndarray:

pandas/core/arrays/datetimelike.py

-1
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,6 @@ def view(self, dtype: Literal["m8[ns]"]) -> TimedeltaArray: ...
506506
@overload
507507
def view(self, dtype: Dtype | None = ...) -> ArrayLike: ...
508508

509-
# pylint: disable-next=useless-parent-delegation
510509
def view(self, dtype: Dtype | None = None) -> ArrayLike:
511510
# we need to explicitly call super() method as long as the `@overload`s
512511
# are present in this file.

pandas/core/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def __sizeof__(self) -> int:
127127
"""
128128
memory_usage = getattr(self, "memory_usage", None)
129129
if memory_usage:
130-
mem = memory_usage(deep=True) # pylint: disable=not-callable
130+
mem = memory_usage(deep=True)
131131
return int(mem if is_scalar(mem) else mem.sum())
132132

133133
# no memory_usage attribute, so fall back to object's 'sizeof'

pandas/core/dtypes/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def is_scipy_sparse(arr) -> bool:
250250
"""
251251
global _is_scipy_sparse
252252

253-
if _is_scipy_sparse is None: # pylint: disable=used-before-assignment
253+
if _is_scipy_sparse is None:
254254
try:
255255
from scipy.sparse import issparse as _is_scipy_sparse
256256
except ImportError:

pandas/core/groupby/groupby.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5014,7 +5014,7 @@ def shift(
50145014
period = cast(int, period)
50155015
if freq is not None:
50165016
f = lambda x: x.shift(
5017-
period, # pylint: disable=cell-var-from-loop
5017+
period,
50185018
freq,
50195019
0, # axis
50205020
fill_value,

pandas/core/indexes/multi.py

-1
Original file line numberDiff line numberDiff line change
@@ -2803,7 +2803,6 @@ def get_slice_bound(
28032803
label = (label,)
28042804
return self._partial_tup_index(label, side=side)
28052805

2806-
# pylint: disable-next=useless-parent-delegation
28072806
def slice_locs(self, start=None, end=None, step=None) -> tuple[int, int]:
28082807
"""
28092808
For an ordered MultiIndex, compute the slice locations for input

pandas/core/internals/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
)
77

88
__all__ = [
9-
"Block", # pylint: disable=undefined-all-variable
10-
"DatetimeTZBlock", # pylint: disable=undefined-all-variable
11-
"ExtensionBlock", # pylint: disable=undefined-all-variable
9+
"Block",
10+
"DatetimeTZBlock",
11+
"ExtensionBlock",
1212
"make_block",
1313
"BlockManager",
1414
"SingleBlockManager",

pandas/core/series.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,6 @@ def __repr__(self) -> str:
14691469
"""
14701470
Return a string representation for a particular Series.
14711471
"""
1472-
# pylint: disable=invalid-repr-returned
14731472
repr_params = fmt.get_series_repr_params()
14741473
return self.to_string(**repr_params)
14751474

@@ -2059,7 +2058,7 @@ def mode(self, dropna: bool = True) -> Series:
20592058
dtype=self.dtype,
20602059
).__finalize__(self, method="mode")
20612060

2062-
def unique(self) -> ArrayLike: # pylint: disable=useless-parent-delegation
2061+
def unique(self) -> ArrayLike:
20632062
"""
20642063
Return unique values of Series object.
20652064

pandas/io/formats/style.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3038,7 +3038,7 @@ def set_properties(self, subset: Subset | None = None, **kwargs) -> Styler:
30383038
return self.map(lambda x: values, subset=subset)
30393039

30403040
@Substitution(subset=subset_args)
3041-
def bar( # pylint: disable=disallowed-name
3041+
def bar(
30423042
self,
30433043
subset: Subset | None = None,
30443044
axis: Axis | None = 0,

pandas/plotting/_core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ def line(
11871187
)
11881188
@Substitution(kind="bar")
11891189
@Appender(_bar_or_line_doc)
1190-
def bar( # pylint: disable=disallowed-name
1190+
def bar(
11911191
self,
11921192
x: Hashable | None = None,
11931193
y: Hashable | None = None,

pandas/plotting/_matplotlib/boxplot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __init__(self, data, return_type: str = "axes", **kwargs) -> None:
8282

8383
self.return_type = return_type
8484
# Do not call LinePlot.__init__ which may fill nan
85-
MPLPlot.__init__(self, data, **kwargs) # pylint: disable=non-parent-init-called
85+
MPLPlot.__init__(self, data, **kwargs)
8686

8787
if self.subplots:
8888
# Disable label ax sharing. Otherwise, all subplots shows last

pandas/plotting/_matplotlib/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def __init__(
297297
def _validate_sharex(sharex: bool | None, ax, by) -> bool:
298298
if sharex is None:
299299
# if by is defined, subplots are used and sharex should be False
300-
if ax is None and by is None: # pylint: disable=simplifiable-if-statement
300+
if ax is None and by is None:
301301
sharex = True
302302
else:
303303
# if we get an axis, the users should do the visibility

pandas/plotting/_matplotlib/hist.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __init__(
7878
self.xlabel = kwargs.get("xlabel")
7979
self.ylabel = kwargs.get("ylabel")
8080
# Do not call LinePlot.__init__ which may fill nan
81-
MPLPlot.__init__(self, data, **kwargs) # pylint: disable=non-parent-init-called
81+
MPLPlot.__init__(self, data, **kwargs)
8282

8383
self.bins = self._adjust_bins(bins)
8484

@@ -236,7 +236,7 @@ def __init__(
236236
self, data, bw_method=None, ind=None, *, weights=None, **kwargs
237237
) -> None:
238238
# Do not call LinePlot.__init__ which may fill nan
239-
MPLPlot.__init__(self, data, **kwargs) # pylint: disable=non-parent-init-called
239+
MPLPlot.__init__(self, data, **kwargs)
240240
self.bw_method = bw_method
241241
self.ind = ind
242242
self.weights = weights

pandas/tests/config/test_config.py

-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ def test_validation(self):
227227

228228
validator = cf.is_one_of_factory([None, cf.is_callable])
229229
cf.register_option("b", lambda: None, "doc", validator=validator)
230-
# pylint: disable-next=consider-using-f-string
231230
cf.set_option("b", "%.1f".format) # Formatter is callable
232231
cf.set_option("b", None) # Formatter is none (default)
233232
with pytest.raises(ValueError, match="Value must be a callable"):

pandas/tests/dtypes/test_inference.py

-2
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,6 @@ def test_is_list_like_generic():
240240
# is_list_like was yielding false positives for Generic classes in python 3.11
241241
T = TypeVar("T")
242242

243-
# https://github.com/pylint-dev/pylint/issues/9398
244-
# pylint: disable=multiple-statements
245243
class MyDataFrame(DataFrame, Generic[T]): ...
246244

247245
tstc = MyDataFrame[int]

pandas/tests/groupby/test_grouping.py

-1
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,6 @@ def test_multi_iter_frame(self, three_group):
10441044
grouped = df.groupby(["k1", "k2"])
10451045
# calling `dict` on a DataFrameGroupBy leads to a TypeError,
10461046
# we need to use a dictionary comprehension here
1047-
# pylint: disable-next=unnecessary-comprehension
10481047
groups = {key: gp for key, gp in grouped} # noqa: C416
10491048
assert len(groups) == 2
10501049

pandas/tests/indexes/datetimes/test_iter.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_iteration_preserves_nanoseconds(self, tz):
2020
["2018-02-08 15:00:00.168456358", "2018-02-08 15:00:00.168456359"], tz=tz
2121
)
2222
for i, ts in enumerate(index):
23-
assert ts == index[i] # pylint: disable=unnecessary-list-index-lookup
23+
assert ts == index[i]
2424

2525
def test_iter_readonly(self):
2626
# GH#28055 ints_to_pydatetime with readonly array
@@ -35,7 +35,7 @@ def test_iteration_preserves_tz(self):
3535

3636
for i, ts in enumerate(index):
3737
result = ts
38-
expected = index[i] # pylint: disable=unnecessary-list-index-lookup
38+
expected = index[i]
3939
assert result == expected
4040

4141
def test_iteration_preserves_tz2(self):
@@ -45,7 +45,7 @@ def test_iteration_preserves_tz2(self):
4545

4646
for i, ts in enumerate(index):
4747
result = ts
48-
expected = index[i] # pylint: disable=unnecessary-list-index-lookup
48+
expected = index[i]
4949
assert result._repr_base == expected._repr_base
5050
assert result == expected
5151

@@ -56,7 +56,7 @@ def test_iteration_preserves_tz3(self):
5656
)
5757
for i, ts in enumerate(index):
5858
result = ts
59-
expected = index[i] # pylint: disable=unnecessary-list-index-lookup
59+
expected = index[i]
6060
assert result._repr_base == expected._repr_base
6161
assert result == expected
6262

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

-1
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,6 @@ def test_rendered_links(type, text, exp, found):
821821

822822
def test_multiple_rendered_links():
823823
links = ("www.a.b", "http://a.c", "https://a.d", "ftp://a.e")
824-
# pylint: disable-next=consider-using-f-string
825824
df = DataFrame(["text {} {} text {} {}".format(*links)])
826825
result = df.style.format(hyperlinks="html").to_html()
827826
href = '<a href="{0}" target="_blank">{0}</a>'

pandas/tests/io/test_html.py

-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ def test_to_html_compat(self, flavor_read_html):
152152
np.random.default_rng(2).random((4, 3)),
153153
columns=pd.Index(list("abc"), dtype=object),
154154
)
155-
# pylint: disable-next=consider-using-f-string
156155
.map("{:.3f}".format)
157156
.astype(float)
158157
)
@@ -1460,7 +1459,6 @@ def seek(self, offset):
14601459
def seekable(self):
14611460
return True
14621461

1463-
# GH 49036 pylint checks for presence of __next__ for iterators
14641462
def __next__(self): ...
14651463

14661464
def __iter__(self) -> Iterator:

pandas/tests/reshape/test_pivot.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ def test_pivot_columns_none_raise_error(self):
819819
df = DataFrame({"col1": ["a", "b", "c"], "col2": [1, 2, 3], "col3": [1, 2, 3]})
820820
msg = r"pivot\(\) missing 1 required keyword-only argument: 'columns'"
821821
with pytest.raises(TypeError, match=msg):
822-
df.pivot(index="col1", values="col3") # pylint: disable=missing-kwoa
822+
df.pivot(index="col1", values="col3")
823823

824824
@pytest.mark.xfail(
825825
reason="MultiIndexed unstack with tuple names fails with KeyError GH#19966"
@@ -2600,7 +2600,7 @@ def test_pivot_columns_not_given(self):
26002600
# GH#48293
26012601
df = DataFrame({"a": [1], "b": 1})
26022602
with pytest.raises(TypeError, match="missing 1 required keyword-only argument"):
2603-
df.pivot() # pylint: disable=missing-kwoa
2603+
df.pivot()
26042604

26052605
@pytest.mark.xfail(using_pyarrow_string_dtype(), reason="None is cast to NaN")
26062606
def test_pivot_columns_is_none(self):

pandas/tests/scalar/timedelta/test_arithmetic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1180,5 +1180,5 @@ def test_ops_error_str():
11801180
with pytest.raises(TypeError, match=msg):
11811181
left > right
11821182

1183-
assert not left == right # pylint: disable=unneeded-not
1183+
assert not left == right
11841184
assert left != right

pandas/tests/scalar/timestamp/test_comparisons.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,5 +309,5 @@ def __eq__(self, other) -> bool:
309309
for left, right in [(inf, timestamp), (timestamp, inf)]:
310310
assert left > right or left < right
311311
assert left >= right or left <= right
312-
assert not left == right # pylint: disable=unneeded-not
312+
assert not left == right
313313
assert left != right

pandas/tests/util/test_deprecate_nonkeyword_arguments.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ def test_i_signature():
124124

125125
class Foo:
126126
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "bar"])
127-
def baz(self, bar=None, foobar=None): # pylint: disable=disallowed-name
128-
...
127+
def baz(self, bar=None, foobar=None): ...
129128

130129

131130
def test_foo_signature():

0 commit comments

Comments
 (0)