Skip to content

Commit 4da06f1

Browse files
committed
Replace flake8 and pyupgrade with ruff
1 parent 89e083b commit 4da06f1

File tree

6 files changed

+26
-42
lines changed

6 files changed

+26
-42
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,16 @@ 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, _*.pyi:PYI030"
3623
]
3724
- repo: https://github.com/codespell-project/codespell
3825
rev: v2.2.5

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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ DtypeArg: TypeAlias = Dtype | Mapping[Any, Dtype]
8080
DtypeBackend: TypeAlias = Literal["pyarrow", "numpy_nullable"]
8181
BooleanDtypeArg: TypeAlias = (
8282
# Builtin bool type and its string alias
83-
type[bool] # noqa: Y030
83+
type[bool]
8484
| Literal["bool"]
8585
# Pandas nullable boolean type and its string alias
8686
| pd.BooleanDtype
@@ -90,7 +90,7 @@ BooleanDtypeArg: TypeAlias = (
9090
)
9191
IntDtypeArg: TypeAlias = (
9292
# Builtin integer type and its string alias
93-
type[int] # noqa: Y030
93+
type[int]
9494
| Literal["int"]
9595
# Pandas nullable integer types and their string aliases
9696
| pd.Int8Dtype
@@ -117,7 +117,7 @@ IntDtypeArg: TypeAlias = (
117117
)
118118
StrDtypeArg: TypeAlias = (
119119
# Builtin str type and its string alias
120-
type[str] # noqa: Y030
120+
type[str]
121121
| Literal["str"]
122122
# Pandas nullable string type and its string alias
123123
| pd.StringDtype
@@ -126,7 +126,7 @@ StrDtypeArg: TypeAlias = (
126126
BytesDtypeArg: TypeAlias = type[bytes]
127127
FloatDtypeArg: TypeAlias = (
128128
# Builtin float type and its string alias
129-
type[float] # noqa: Y030
129+
type[float]
130130
| Literal["float"]
131131
# Pandas nullable float types and their string aliases
132132
| pd.Float32Dtype
@@ -140,7 +140,7 @@ FloatDtypeArg: TypeAlias = (
140140
)
141141
ComplexDtypeArg: TypeAlias = (
142142
# Builtin complex type and its string alias
143-
type[complex] # noqa: Y030
143+
type[complex]
144144
| Literal["complex"]
145145
# Numpy complex types and their aliases
146146
| type[np.complex64]

pandas-stubs/core/generic.pyi

Lines changed: 1 addition & 2 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 (
@@ -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/indexes/accessors.pyi

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ class Properties(PandasDelegate, PandasObject, NoNewAttributesMixin):
4646
_DTFieldOpsReturnType = TypeVar("_DTFieldOpsReturnType", Series[int], _IntIndexType)
4747

4848
class _DatetimeFieldOps(
49-
_DayLikeFieldOps[_DTFieldOpsReturnType], _MiniSeconds[_DTFieldOpsReturnType]
49+
_DayLikeFieldOps[_DTFieldOpsReturnType], # noqa: F821
50+
_MiniSeconds[_DTFieldOpsReturnType], # noqa: F821
5051
): ...
5152
class PeriodIndexFieldOps(
52-
_DayLikeFieldOps[_IntIndexType],
53-
_PeriodProperties[DatetimeIndex, _IntIndexType, Index, DatetimeIndex, PeriodIndex],
53+
_DayLikeFieldOps[_IntIndexType], # noqa: F821
54+
_PeriodProperties[ # noqa: F821
55+
DatetimeIndex, _IntIndexType, Index, DatetimeIndex, PeriodIndex
56+
],
5457
): ...
5558

5659
class _DayLikeFieldOps(Generic[_DTFieldOpsReturnType]):

tests/test_timefuncs.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
# flake8: noqa: F841
21
from __future__ import annotations
32

43
import datetime as dt
54
from typing import (
65
TYPE_CHECKING,
76
Any,
87
Optional,
9-
Union,
108
)
119

1210
import numpy as np
@@ -43,11 +41,9 @@
4341
)
4442

4543
if TYPE_CHECKING:
46-
from pandas.core.series import (
47-
PeriodSeries,
48-
TimedeltaSeries,
49-
TimestampSeries,
50-
)
44+
from pandas.core.series import PeriodSeries # noqa: F401
45+
from pandas.core.series import TimedeltaSeries # noqa: F401
46+
from pandas.core.series import TimestampSeries # noqa: F401
5147

5248
if TYPE_CHECKING:
5349
from pandas.core.indexes.base import _IntIndexType
@@ -310,15 +306,15 @@ def test_to_datetime_nat() -> None:
310306
check(
311307
assert_type(
312308
pd.to_datetime("2021-03-01", errors="coerce"),
313-
"Union[pd.Timestamp, NaTType]",
309+
"pd.Timestamp | NaTType",
314310
),
315311
pd.Timestamp,
316312
)
317313

318314
check(
319315
assert_type(
320316
pd.to_datetime("not a date", errors="coerce"),
321-
"Union[pd.Timestamp, NaTType]",
317+
"pd.Timestamp | NaTType",
322318
),
323319
NaTType,
324320
)

0 commit comments

Comments
 (0)