Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate pylint to ruff #57182

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
echo "PYTHONPATH=$PYTHONPATH" >> $GITHUB_ENV
if: ${{ steps.build.outcome == 'success' && always() }}

- name: Typing + pylint
- name: Typing
uses: pre-commit/[email protected]
with:
extra_args: --verbose --hook-stage manual --all-files
Expand Down
21 changes: 1 addition & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ci:
autofix_prs: false
autoupdate_schedule: monthly
# manual stage hooks
skip: [pylint, pyright, mypy]
skip: [pyright, mypy]
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4
Expand Down Expand Up @@ -67,25 +67,6 @@ repos:
- id: fix-encoding-pragma
args: [--remove]
- id: trailing-whitespace
- repo: https://github.com/pylint-dev/pylint
rev: v3.0.1
hooks:
- id: pylint
stages: [manual]
args: [--load-plugins=pylint.extensions.redefined_loop_name, --fail-on=I0021]
- id: pylint
alias: redefined-outer-name
name: Redefining name from outer scope
files: ^pandas/
exclude: |
(?x)
^pandas/tests # keep excluded
|/_testing/ # keep excluded
|^pandas/util/_test_decorators\.py # keep excluded
|^pandas/_version\.py # keep excluded
|^pandas/conftest\.py # keep excluded
args: [--disable=all, --enable=redefined-outer-name]
stages: [manual]
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"is_supported_dtype",
]

from pandas._libs.tslibs import dtypes # pylint: disable=import-self
from pandas._libs.tslibs import dtypes
from pandas._libs.tslibs.conversion import localize_pydatetime
from pandas._libs.tslibs.dtypes import (
Resolution,
Expand Down
1 change: 0 additions & 1 deletion pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2482,7 +2482,6 @@ def unique(self) -> Self:
['b', 'a']
Categories (3, object): ['a' < 'b' < 'c']
"""
# pylint: disable=useless-parent-delegation
return super().unique()

def _cast_quantile_result(self, res_values: np.ndarray) -> np.ndarray:
Expand Down
1 change: 0 additions & 1 deletion pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ def view(self, dtype: Literal["m8[ns]"]) -> TimedeltaArray: ...
@overload
def view(self, dtype: Dtype | None = ...) -> ArrayLike: ...

# pylint: disable-next=useless-parent-delegation
def view(self, dtype: Dtype | None = None) -> ArrayLike:
# we need to explicitly call super() method as long as the `@overload`s
# are present in this file.
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def __sizeof__(self) -> int:
"""
memory_usage = getattr(self, "memory_usage", None)
if memory_usage:
mem = memory_usage(deep=True) # pylint: disable=not-callable
mem = memory_usage(deep=True)
return int(mem if is_scalar(mem) else mem.sum())

# no memory_usage attribute, so fall back to object's 'sizeof'
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def is_scipy_sparse(arr) -> bool:
"""
global _is_scipy_sparse

if _is_scipy_sparse is None: # pylint: disable=used-before-assignment
if _is_scipy_sparse is None:
try:
from scipy.sparse import issparse as _is_scipy_sparse
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -5014,7 +5014,7 @@ def shift(
period = cast(int, period)
if freq is not None:
f = lambda x: x.shift(
period, # pylint: disable=cell-var-from-loop
period,
freq,
0, # axis
fill_value,
Expand Down
1 change: 0 additions & 1 deletion pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2803,7 +2803,6 @@ def get_slice_bound(
label = (label,)
return self._partial_tup_index(label, side=side)

# pylint: disable-next=useless-parent-delegation
def slice_locs(self, start=None, end=None, step=None) -> tuple[int, int]:
"""
For an ordered MultiIndex, compute the slice locations for input
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/internals/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
)

__all__ = [
"Block", # pylint: disable=undefined-all-variable
"DatetimeTZBlock", # pylint: disable=undefined-all-variable
"ExtensionBlock", # pylint: disable=undefined-all-variable
"Block",
"DatetimeTZBlock",
"ExtensionBlock",
"make_block",
"BlockManager",
"SingleBlockManager",
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,6 @@ def __repr__(self) -> str:
"""
Return a string representation for a particular Series.
"""
# pylint: disable=invalid-repr-returned
repr_params = fmt.get_series_repr_params()
return self.to_string(**repr_params)

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

def unique(self) -> ArrayLike: # pylint: disable=useless-parent-delegation
def unique(self) -> ArrayLike:
"""
Return unique values of Series object.

Expand Down
2 changes: 1 addition & 1 deletion pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -3038,7 +3038,7 @@ def set_properties(self, subset: Subset | None = None, **kwargs) -> Styler:
return self.map(lambda x: values, subset=subset)

@Substitution(subset=subset_args)
def bar( # pylint: disable=disallowed-name
def bar(
self,
subset: Subset | None = None,
axis: Axis | None = 0,
Expand Down
2 changes: 1 addition & 1 deletion pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ def line(
)
@Substitution(kind="bar")
@Appender(_bar_or_line_doc)
def bar( # pylint: disable=disallowed-name
def bar(
self,
x: Hashable | None = None,
y: Hashable | None = None,
Expand Down
2 changes: 1 addition & 1 deletion pandas/plotting/_matplotlib/boxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(self, data, return_type: str = "axes", **kwargs) -> None:

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

if self.subplots:
# Disable label ax sharing. Otherwise, all subplots shows last
Expand Down
2 changes: 1 addition & 1 deletion pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def __init__(
def _validate_sharex(sharex: bool | None, ax, by) -> bool:
if sharex is None:
# if by is defined, subplots are used and sharex should be False
if ax is None and by is None: # pylint: disable=simplifiable-if-statement
if ax is None and by is None:
sharex = True
else:
# if we get an axis, the users should do the visibility
Expand Down
4 changes: 2 additions & 2 deletions pandas/plotting/_matplotlib/hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(
self.xlabel = kwargs.get("xlabel")
self.ylabel = kwargs.get("ylabel")
# Do not call LinePlot.__init__ which may fill nan
MPLPlot.__init__(self, data, **kwargs) # pylint: disable=non-parent-init-called
MPLPlot.__init__(self, data, **kwargs)

self.bins = self._adjust_bins(bins)

Expand Down Expand Up @@ -236,7 +236,7 @@ def __init__(
self, data, bw_method=None, ind=None, *, weights=None, **kwargs
) -> None:
# Do not call LinePlot.__init__ which may fill nan
MPLPlot.__init__(self, data, **kwargs) # pylint: disable=non-parent-init-called
MPLPlot.__init__(self, data, **kwargs)
self.bw_method = bw_method
self.ind = ind
self.weights = weights
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ def test_validation(self):

validator = cf.is_one_of_factory([None, cf.is_callable])
cf.register_option("b", lambda: None, "doc", validator=validator)
# pylint: disable-next=consider-using-f-string
cf.set_option("b", "%.1f".format) # Formatter is callable
cf.set_option("b", None) # Formatter is none (default)
with pytest.raises(ValueError, match="Value must be a callable"):
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/dtypes/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,6 @@ def test_is_list_like_generic():
# is_list_like was yielding false positives for Generic classes in python 3.11
T = TypeVar("T")

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

tstc = MyDataFrame[int]
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/groupby/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,6 @@ def test_multi_iter_frame(self, three_group):
grouped = df.groupby(["k1", "k2"])
# calling `dict` on a DataFrameGroupBy leads to a TypeError,
# we need to use a dictionary comprehension here
# pylint: disable-next=unnecessary-comprehension
groups = {key: gp for key, gp in grouped} # noqa: C416
assert len(groups) == 2

Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/indexes/datetimes/test_iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_iteration_preserves_nanoseconds(self, tz):
["2018-02-08 15:00:00.168456358", "2018-02-08 15:00:00.168456359"], tz=tz
)
for i, ts in enumerate(index):
assert ts == index[i] # pylint: disable=unnecessary-list-index-lookup
assert ts == index[i]

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

for i, ts in enumerate(index):
result = ts
expected = index[i] # pylint: disable=unnecessary-list-index-lookup
expected = index[i]
assert result == expected

def test_iteration_preserves_tz2(self):
Expand All @@ -45,7 +45,7 @@ def test_iteration_preserves_tz2(self):

for i, ts in enumerate(index):
result = ts
expected = index[i] # pylint: disable=unnecessary-list-index-lookup
expected = index[i]
assert result._repr_base == expected._repr_base
assert result == expected

Expand All @@ -56,7 +56,7 @@ def test_iteration_preserves_tz3(self):
)
for i, ts in enumerate(index):
result = ts
expected = index[i] # pylint: disable=unnecessary-list-index-lookup
expected = index[i]
assert result._repr_base == expected._repr_base
assert result == expected

Expand Down
1 change: 0 additions & 1 deletion pandas/tests/io/formats/style/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,6 @@ def test_rendered_links(type, text, exp, found):

def test_multiple_rendered_links():
links = ("www.a.b", "http://a.c", "https://a.d", "ftp://a.e")
# pylint: disable-next=consider-using-f-string
df = DataFrame(["text {} {} text {} {}".format(*links)])
result = df.style.format(hyperlinks="html").to_html()
href = '<a href="{0}" target="_blank">{0}</a>'
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/io/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ def test_to_html_compat(self, flavor_read_html):
np.random.default_rng(2).random((4, 3)),
columns=pd.Index(list("abc"), dtype=object),
)
# pylint: disable-next=consider-using-f-string
.map("{:.3f}".format)
.astype(float)
)
Expand Down Expand Up @@ -1460,7 +1459,6 @@ def seek(self, offset):
def seekable(self):
return True

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

def __iter__(self) -> Iterator:
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/reshape/test_pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ def test_pivot_columns_none_raise_error(self):
df = DataFrame({"col1": ["a", "b", "c"], "col2": [1, 2, 3], "col3": [1, 2, 3]})
msg = r"pivot\(\) missing 1 required keyword-only argument: 'columns'"
with pytest.raises(TypeError, match=msg):
df.pivot(index="col1", values="col3") # pylint: disable=missing-kwoa
df.pivot(index="col1", values="col3")

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

@pytest.mark.xfail(using_pyarrow_string_dtype(), reason="None is cast to NaN")
def test_pivot_columns_is_none(self):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/scalar/timedelta/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,5 +1180,5 @@ def test_ops_error_str():
with pytest.raises(TypeError, match=msg):
left > right

assert not left == right # pylint: disable=unneeded-not
assert not left == right
assert left != right
2 changes: 1 addition & 1 deletion pandas/tests/scalar/timestamp/test_comparisons.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,5 +309,5 @@ def __eq__(self, other) -> bool:
for left, right in [(inf, timestamp), (timestamp, inf)]:
assert left > right or left < right
assert left >= right or left <= right
assert not left == right # pylint: disable=unneeded-not
assert not left == right
assert left != right
3 changes: 1 addition & 2 deletions pandas/tests/util/test_deprecate_nonkeyword_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ def test_i_signature():

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


def test_foo_signature():
Expand Down
Loading