From 7fedfa8546d0e8b5e3f1e5839a2c45498f51244f Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Fri, 5 Apr 2024 10:10:06 -0700 Subject: [PATCH 1/3] Use noqa instead of a pre-commit section --- .pre-commit-config.yaml | 6 ------ pandas/core/api.py | 2 +- pyproject.toml | 2 ++ 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b8726e058a52b..8eec5d5515239 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,12 +30,6 @@ repos: files: ^pandas exclude: ^pandas/tests args: [--select, "ANN001,ANN2", --fix-only, --exit-non-zero-on-fix] - - id: ruff - name: ruff-use-pd_array-in-core - alias: ruff-use-pd_array-in-core - files: ^pandas/core/ - exclude: ^pandas/core/api\.py$ - args: [--select, "ICN001", --exit-non-zero-on-fix] - id: ruff-format exclude: ^scripts - repo: https://github.com/jendrikseipp/vulture diff --git a/pandas/core/api.py b/pandas/core/api.py index 3d2e855831c05..c8a4e9d8a23b2 100644 --- a/pandas/core/api.py +++ b/pandas/core/api.py @@ -41,7 +41,7 @@ UInt64Dtype, ) from pandas.core.arrays.string_ import StringDtype -from pandas.core.construction import array +from pandas.core.construction import array # noqa: ICN001 from pandas.core.flags import Flags from pandas.core.groupby import ( Grouper, diff --git a/pyproject.toml b/pyproject.toml index c9180cf04e7f5..9d6fb5170e624 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -234,6 +234,8 @@ select = [ "G", # flake8-future-annotations "FA", + # unconventional-import-alias + "ICN001", ] ignore = [ From 5b2e4d008b18aa6c65ae322aecdf8cbf7c2f0b9f Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Fri, 5 Apr 2024 10:36:16 -0700 Subject: [PATCH 2/3] Add refurb rule --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 9d6fb5170e624..9a401aef4c920 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -236,6 +236,8 @@ select = [ "FA", # unconventional-import-alias "ICN001", + # refurb + "FURB", ] ignore = [ From 3033404dea13b3e080e0bd4b878ee9a540dd1cce Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Fri, 5 Apr 2024 10:41:45 -0700 Subject: [PATCH 3/3] Add flake8-slots/raise --- pandas/core/generic.py | 2 +- pandas/core/indexing.py | 4 ++-- pandas/core/interchange/buffer.py | 2 +- pandas/io/stata.py | 4 ++-- pandas/tests/config/test_localization.py | 2 +- pandas/tests/frame/indexing/test_setitem.py | 2 +- pyproject.toml | 6 ++++-- 7 files changed, 12 insertions(+), 10 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 99462917599e1..8af9503a3691d 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6729,7 +6729,7 @@ def _pad_or_backfill( if axis == 1: if not self._mgr.is_single_block and inplace: - raise NotImplementedError() + raise NotImplementedError # e.g. test_align_fill_method result = self.T._pad_or_backfill( method=method, limit=limit, limit_area=limit_area diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 982e305b7e471..a834d3e54d30b 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -1191,13 +1191,13 @@ def __getitem__(self, key): return self._getitem_axis(maybe_callable, axis=axis) def _is_scalar_access(self, key: tuple): - raise NotImplementedError() + raise NotImplementedError def _getitem_tuple(self, tup: tuple): raise AbstractMethodError(self) def _getitem_axis(self, key, axis: AxisInt): - raise NotImplementedError() + raise NotImplementedError def _has_valid_setitem_indexer(self, indexer) -> bool: raise AbstractMethodError(self) diff --git a/pandas/core/interchange/buffer.py b/pandas/core/interchange/buffer.py index 5d24325e67f62..62bf396256f2a 100644 --- a/pandas/core/interchange/buffer.py +++ b/pandas/core/interchange/buffer.py @@ -114,7 +114,7 @@ def __dlpack__(self) -> Any: """ Represent this structure as DLPack interface. """ - raise NotImplementedError() + raise NotImplementedError def __dlpack_device__(self) -> tuple[DlpackDeviceType, int | None]: """ diff --git a/pandas/io/stata.py b/pandas/io/stata.py index 3ec077806d6c4..50ee2d52ee51d 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -1376,7 +1376,7 @@ def _get_time_stamp(self) -> str: elif self._format_version > 104: return self._decode(self._path_or_buf.read(18)) else: - raise ValueError() + raise ValueError def _get_seek_variable_labels(self) -> int: if self._format_version == 117: @@ -1388,7 +1388,7 @@ def _get_seek_variable_labels(self) -> int: elif self._format_version >= 118: return self._read_int64() + 17 else: - raise ValueError() + raise ValueError def _read_old_header(self, first_char: bytes) -> None: self._format_version = int(first_char[0]) diff --git a/pandas/tests/config/test_localization.py b/pandas/tests/config/test_localization.py index 844f67cd2d0ea..b9a0a44bf8c89 100644 --- a/pandas/tests/config/test_localization.py +++ b/pandas/tests/config/test_localization.py @@ -92,7 +92,7 @@ def test_can_set_locale_invalid_get(monkeypatch): # but a subsequent getlocale() raises a ValueError. def mock_get_locale(): - raise ValueError() + raise ValueError with monkeypatch.context() as m: m.setattr(locale, "getlocale", mock_get_locale) diff --git a/pandas/tests/frame/indexing/test_setitem.py b/pandas/tests/frame/indexing/test_setitem.py index 658fafd3ea2cc..3f98f49cd1877 100644 --- a/pandas/tests/frame/indexing/test_setitem.py +++ b/pandas/tests/frame/indexing/test_setitem.py @@ -41,7 +41,7 @@ class TestDataFrameSetItem: def test_setitem_str_subclass(self): # GH#37366 class mystring(str): - pass + __slots__ = () data = ["2020-10-22 01:21:00+00:00"] index = DatetimeIndex(data) diff --git a/pyproject.toml b/pyproject.toml index 9a401aef4c920..0a0a3e8b484f0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -236,8 +236,10 @@ select = [ "FA", # unconventional-import-alias "ICN001", - # refurb - "FURB", + # flake8-slots + "SLOT", + # flake8-raise + "RSE" ] ignore = [