Skip to content

Commit 6769e81

Browse files
authored
Replace flake8 and pyupgrade with ruff (#754)
* Replace flake8 and pyupgrade with ruff * applied autofixes from ANN204 but disabled it because we have too many special methods without return types * black * Use Self * Allow mypy to use incremental runs * Revert "Allow mypy to use incremental runs" This reverts commit b3673c3. * line-based ignores for PYI030 * fix merge
1 parent 490914f commit 6769e81

20 files changed

+76
-93
lines changed

.pre-commit-config.yaml

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,17 @@ repos:
1010
rev: 5.12.0
1111
hooks:
1212
- id: isort
13-
- repo: https://github.com/asottile/pyupgrade
14-
rev: v3.9.0
13+
- repo: https://github.com/astral-sh/ruff-pre-commit
14+
rev: v0.0.278
1515
hooks:
16-
- id: pyupgrade
17-
types_or: [python, pyi]
18-
types: [text] # overwrite types: [python]
19-
args: [--py38-plus]
20-
- repo: https://github.com/PyCQA/flake8
21-
rev: 6.0.0
22-
hooks:
23-
- id: flake8
24-
name: flake8 (py)
25-
types: [python]
26-
args: [--ignore=E501 F841]
27-
- id: flake8
28-
name: flake8 (pyi)
29-
additional_dependencies:
30-
- flake8-pyi==23.6.0
31-
types: [pyi]
16+
- id: ruff
3217
args: [
33-
--ignore=E301 E302 E305 E402 E501 E701 E704 F401 F811 F821 W503 Y042,
34-
# TypeVars in private files are already private
35-
--per-file-ignores=_*.pyi:Y001
18+
--exit-non-zero-on-fix,
19+
--target-version, py38,
20+
--extend-select, "PYI,UP,RUF100",
21+
--ignore, "E501,E731,F841,PYI042",
22+
--per-file-ignores, "_*.pyi:PYI001",
23+
--fix
3624
]
3725
- repo: https://github.com/codespell-project/codespell
3826
rev: v2.2.5

pandas-stubs/_libs/interval.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
7979
left: _OrderableT,
8080
right: _OrderableT,
8181
closed: IntervalClosedType = ...,
82-
): ...
82+
) -> None: ...
8383
def __hash__(self) -> int: ...
8484
# for __contains__, it seems that we have to separate out the 4 cases to make
8585
# mypy happy
@@ -222,7 +222,7 @@ class IntervalTree(IntervalMixin):
222222
right: np.ndarray,
223223
closed: IntervalClosedType = ...,
224224
leaf_size: int = ...,
225-
): ...
225+
) -> None: ...
226226
def get_indexer(self, target) -> npt.NDArray[np.intp]: ...
227227
def get_indexer_non_unique(
228228
self, target

pandas-stubs/_libs/tslibs/offsets.pyi

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class RelativeDeltaOffset(BaseOffset):
123123
class BusinessMixin(SingleConstructorOffset):
124124
def __init__(
125125
self, n: int = ..., normalize: bool = ..., offset: timedelta = ...
126-
): ...
126+
) -> None: ...
127127

128128
class BusinessDay(BusinessMixin): ...
129129

@@ -135,15 +135,17 @@ class BusinessHour(BusinessMixin):
135135
start: str | time | Collection[str | time] = ...,
136136
end: str | time | Collection[str | time] = ...,
137137
offset: timedelta = ...,
138-
): ...
138+
) -> None: ...
139139

140140
class WeekOfMonthMixin(SingleConstructorOffset):
141-
def __init__(self, n: int = ..., weekday: Literal[0, 1, 2, 3, 4, 5, 6] = ...): ...
141+
def __init__(
142+
self, n: int = ..., weekday: Literal[0, 1, 2, 3, 4, 5, 6] = ...
143+
) -> None: ...
142144

143145
class YearOffset(SingleConstructorOffset):
144146
def __init__(
145147
self, n: int = ..., normalize: bool = ..., month: int | None = ...
146-
): ...
148+
) -> None: ...
147149

148150
class BYearEnd(YearOffset): ...
149151
class BYearBegin(YearOffset): ...
@@ -206,7 +208,7 @@ class _CustomBusinessMonth(BusinessMixin):
206208
normalize: bool = ...,
207209
offset: timedelta = ...,
208210
holidays: list | None = ...,
209-
): ...
211+
) -> None: ...
210212

211213
class CustomBusinessDay(BusinessDay):
212214
def __init__(
@@ -215,7 +217,7 @@ class CustomBusinessDay(BusinessDay):
215217
normalize: bool = ...,
216218
holidays: list = ...,
217219
calendar: AbstractHolidayCalendar | np.busdaycalendar = ...,
218-
): ...
220+
) -> None: ...
219221

220222
class CustomBusinessHour(BusinessHour):
221223
def __init__(
@@ -226,7 +228,7 @@ class CustomBusinessHour(BusinessHour):
226228
end: str | time | Collection[str | time] = ...,
227229
offset: timedelta = ...,
228230
holidays: list | None = ...,
229-
): ...
231+
) -> None: ...
230232

231233
class CustomBusinessMonthEnd(_CustomBusinessMonth): ...
232234
class CustomBusinessMonthBegin(_CustomBusinessMonth): ...
@@ -256,7 +258,7 @@ class DateOffset(RelativeDeltaOffset):
256258
second: int = ...,
257259
microsecond: int = ...,
258260
nanosecond: int = ...,
259-
): ...
261+
) -> None: ...
260262

261263
BDay = BusinessDay
262264
BMonthEnd = BusinessMonthEnd

pandas-stubs/_libs/tslibs/period.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ from pandas.core.series import (
2020
from typing_extensions import TypeAlias
2121

2222
from pandas._libs.tslibs import NaTType
23+
from pandas._libs.tslibs.offsets import BaseOffset
2324
from pandas._libs.tslibs.timestamps import Timestamp
2425
from pandas._typing import npt
2526

2627
class IncompatibleFrequency(ValueError): ...
2728

28-
from pandas._libs.tslibs.offsets import BaseOffset
29-
3029
_PeriodAddSub: TypeAlias = (
3130
Timedelta | datetime.timedelta | np.timedelta64 | np.int64 | int | BaseOffset
3231
)

pandas-stubs/_typing.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ DtypeBackend: TypeAlias = Literal["pyarrow", "numpy_nullable"]
9191

9292
BooleanDtypeArg: TypeAlias = (
9393
# Builtin bool type and its string alias
94-
type[bool] # noqa: Y030
94+
type[bool] # noqa: PYI030
9595
| Literal["bool"]
9696
# Pandas nullable boolean type and its string alias
9797
| pd.BooleanDtype
@@ -105,7 +105,7 @@ BooleanDtypeArg: TypeAlias = (
105105
)
106106
IntDtypeArg: TypeAlias = (
107107
# Builtin integer type and its string alias
108-
type[int] # noqa: Y030
108+
type[int] # noqa: PYI030
109109
| Literal["int"]
110110
# Pandas nullable integer types and their string aliases
111111
| pd.Int8Dtype
@@ -137,7 +137,7 @@ IntDtypeArg: TypeAlias = (
137137
)
138138
UIntDtypeArg: TypeAlias = (
139139
# Pandas nullable unsigned integer types and their string aliases
140-
pd.UInt8Dtype # noqa: Y030
140+
pd.UInt8Dtype # noqa: PYI030
141141
| pd.UInt16Dtype
142142
| pd.UInt32Dtype
143143
| pd.UInt64Dtype
@@ -166,7 +166,7 @@ UIntDtypeArg: TypeAlias = (
166166
)
167167
FloatDtypeArg: TypeAlias = (
168168
# Builtin float type and its string alias
169-
type[float] # noqa: Y030
169+
type[float] # noqa: PYI030
170170
| Literal["float"]
171171
# Pandas nullable float types and their string aliases
172172
| pd.Float32Dtype
@@ -197,7 +197,7 @@ FloatDtypeArg: TypeAlias = (
197197
)
198198
ComplexDtypeArg: TypeAlias = (
199199
# Builtin complex type and its string alias
200-
type[complex] # noqa: Y030
200+
type[complex] # noqa: PYI030
201201
| Literal["complex"]
202202
# Numpy complex types and their aliases
203203
# https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.csingle
@@ -326,7 +326,7 @@ TimestampDtypeArg: TypeAlias = Literal[
326326

327327
StrDtypeArg: TypeAlias = (
328328
# Builtin str type and its string alias
329-
type[str] # noqa: Y030
329+
type[str] # noqa: PYI030
330330
| Literal["str"]
331331
# Pandas nullable string type and its string alias
332332
| pd.StringDtype
@@ -340,7 +340,7 @@ StrDtypeArg: TypeAlias = (
340340
)
341341
BytesDtypeArg: TypeAlias = (
342342
# Builtin bytes type and its string alias
343-
type[bytes] # noqa: Y030
343+
type[bytes] # noqa: PYI030
344344
| Literal["bytes"]
345345
# Numpy bytes type and its string alias
346346
# https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.bytes_
@@ -353,7 +353,7 @@ CategoryDtypeArg: TypeAlias = CategoricalDtype | Literal["category"]
353353

354354
ObjectDtypeArg: TypeAlias = (
355355
# Builtin object type and its string alias
356-
type[object] # noqa: Y030
356+
type[object] # noqa: PYI030
357357
| Literal["object"]
358358
# Numpy object type and its string alias
359359
# https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.object_

pandas-stubs/core/computation/expr.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class PandasExprVisitor(BaseExprVisitor):
5050
def __init__(self, env, engine, parser, preparser=...) -> None: ...
5151

5252
class PythonExprVisitor(BaseExprVisitor):
53-
def __init__(self, env, engine, parser, preparser=...): ...
53+
def __init__(self, env, engine, parser, preparser=...) -> None: ...
5454

5555
class Expr:
5656
env: Scope

pandas-stubs/core/computation/pytables.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class UnaryOp(ops.UnaryOp):
8181
class PyTablesExprVisitor(BaseExprVisitor):
8282
const_type = ...
8383
term_type = ...
84-
def __init__(self, env, engine, parser, **kwargs): ...
84+
def __init__(self, env, engine, parser, **kwargs) -> None: ...
8585
def visit_UnaryOp(self, node, **kwargs): ...
8686
def visit_Index(self, node, **kwargs): ...
8787
def visit_Assign(self, node, **kwargs): ...

pandas-stubs/core/dtypes/dtypes.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ class DatetimeTZDtype(PandasExtensionDtype):
4848
def na_value(self) -> NaTType: ...
4949

5050
class PeriodDtype(PandasExtensionDtype):
51-
def __init__(self, freq: str | BaseOffset = ...): ...
51+
def __init__(self, freq: str | BaseOffset = ...) -> None: ...
5252
@property
5353
def freq(self) -> BaseOffset: ...
5454
@property
5555
def na_value(self) -> NaTType: ...
5656

5757
class IntervalDtype(PandasExtensionDtype):
58-
def __init__(self, subtype: str | npt.DTypeLike | None = ...): ...
58+
def __init__(self, subtype: str | npt.DTypeLike | None = ...) -> None: ...
5959
@property
6060
def subtype(self) -> np.dtype | None: ...

pandas-stubs/core/frame.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ class DataFrame(NDFrame, OpsMixin):
569569
def isetitem(
570570
self, loc: int | Sequence[int], value: Scalar | ArrayLike | list[Any]
571571
) -> None: ...
572-
def __setitem__(self, key, value): ...
572+
def __setitem__(self, key, value) -> None: ...
573573
@overload
574574
def query(self, expr: _str, *, inplace: Literal[True], **kwargs) -> None: ...
575575
@overload

pandas-stubs/core/generic.pyi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import numpy as np
1818
from pandas import Index
1919
from pandas.core.base import PandasObject
2020
import pandas.core.indexing as indexing
21+
from pandas.core.series import Series
2122
import sqlalchemy.engine
2223

2324
from pandas._typing import (
@@ -286,7 +287,7 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
286287
def take(
287288
self, indices, axis=..., is_copy: _bool | None = ..., **kwargs
288289
) -> NDFrame: ...
289-
def __delitem__(self, idx: Hashable): ...
290+
def __delitem__(self, idx: Hashable) -> None: ...
290291
def get(self, key: object, default: Dtype | None = ...) -> Dtype: ...
291292
def reindex_like(
292293
self,
@@ -479,5 +480,3 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
479480
) -> NDFrame: ...
480481
def first_valid_index(self): ...
481482
def last_valid_index(self): ...
482-
483-
from pandas.core.series import Series

pandas-stubs/core/indexers.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class BaseIndexer:
1616
index_array: np.ndarray | None = ...,
1717
window_size: int = ...,
1818
**kwargs,
19-
): ...
19+
) -> None: ...
2020
def get_window_bounds(
2121
self,
2222
num_values: int = ...,
@@ -33,7 +33,7 @@ class VariableOffsetWindowIndexer(BaseIndexer):
3333
index=...,
3434
offset=...,
3535
**kwargs,
36-
): ...
36+
) -> None: ...
3737
def get_window_bounds(
3838
self,
3939
num_values: int = ...,

pandas-stubs/core/indexes/accessors.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ class Properties(PandasDelegate, PandasObject, NoNewAttributesMixin):
4545

4646
_DTFieldOpsReturnType = TypeVar("_DTFieldOpsReturnType", Series[int], _IntIndexType)
4747

48-
class _DatetimeFieldOps(
49-
_DayLikeFieldOps[_DTFieldOpsReturnType], _MiniSeconds[_DTFieldOpsReturnType]
50-
): ...
51-
class PeriodIndexFieldOps(
52-
_DayLikeFieldOps[_IntIndexType],
53-
_PeriodProperties[DatetimeIndex, _IntIndexType, Index, DatetimeIndex, PeriodIndex],
54-
): ...
55-
5648
class _DayLikeFieldOps(Generic[_DTFieldOpsReturnType]):
5749
@property
5850
def year(self) -> _DTFieldOpsReturnType: ...
@@ -89,6 +81,10 @@ class _MiniSeconds(Generic[_DTFieldOpsReturnType]):
8981
@property
9082
def nanosecond(self) -> _DTFieldOpsReturnType: ...
9183

84+
class _DatetimeFieldOps(
85+
_DayLikeFieldOps[_DTFieldOpsReturnType], _MiniSeconds[_DTFieldOpsReturnType]
86+
): ...
87+
9288
_DTBoolOpsReturnType = TypeVar("_DTBoolOpsReturnType", Series[bool], np_ndarray_bool)
9389

9490
class _IsLeapYearProperty(Generic[_DTBoolOpsReturnType]):
@@ -338,6 +334,10 @@ class _PeriodProperties(
338334
how: Literal["E", "END", "FINISH", "S", "START", "BEGIN"] = ...,
339335
) -> _PeriodPAReturnTypes: ...
340336

337+
class PeriodIndexFieldOps(
338+
_DayLikeFieldOps[_IntIndexType],
339+
_PeriodProperties[DatetimeIndex, _IntIndexType, Index, DatetimeIndex, PeriodIndex],
340+
): ...
341341
class PeriodProperties(
342342
Properties,
343343
_PeriodProperties[

pandas-stubs/core/indexes/datetimes.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class DatetimeIndex( # type: ignore[misc]
5959
dtype=...,
6060
copy: bool = ...,
6161
name=...,
62-
): ...
62+
) -> None: ...
6363
def __array__(self, dtype=...) -> np.ndarray: ...
6464
def __reduce__(self): ...
6565
# various ignores needed for mypy, as we do want to restrict what can be used in

pandas-stubs/core/indexes/range.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class RangeIndex(_IntIndexType):
3333
dtype=...,
3434
copy: bool = ...,
3535
name=...,
36-
): ...
36+
) -> None: ...
3737
@classmethod
3838
def from_range(cls, data, name=..., dtype=...): ...
3939
def __reduce__(self): ...

pandas-stubs/core/indexes/timedeltas.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class TimedeltaIndex( # type: ignore[misc]
4646
dtype: Literal["<m8[ns]"] = ...,
4747
copy: bool = ...,
4848
name: str = ...,
49-
): ...
49+
) -> None: ...
5050
# various ignores needed for mypy, as we do want to restrict what can be used in
5151
# arithmetic for these types
5252
@overload

pandas-stubs/io/formats/style.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ from pandas.io.formats.style_render import (
4040
Subset,
4141
)
4242

43-
class Styler(StylerRenderer[Styler]):
43+
class Styler(StylerRenderer):
4444
def __init__(
4545
self,
4646
data: DataFrame | Series,

0 commit comments

Comments
 (0)