Skip to content

Replace flake8 and pyupgrade with ruff #754

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

Merged
merged 8 commits into from
Jul 25, 2023
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
30 changes: 9 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,17 @@ repos:
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/asottile/pyupgrade
rev: v3.9.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.278
hooks:
- id: pyupgrade
types_or: [python, pyi]
types: [text] # overwrite types: [python]
args: [--py38-plus]
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
name: flake8 (py)
types: [python]
args: [--ignore=E501 F841]
- id: flake8
name: flake8 (pyi)
additional_dependencies:
- flake8-pyi==23.6.0
types: [pyi]
- id: ruff
args: [
--ignore=E301 E302 E305 E402 E501 E701 E704 F401 F811 F821 W503 Y042,
# TypeVars in private files are already private
--per-file-ignores=_*.pyi:Y001
--exit-non-zero-on-fix,
--target-version, py38,
--extend-select, "PYI,UP,RUF100",
--ignore, "E501,E731,F841,PYI042",
--per-file-ignores, "_*.pyi:PYI001",
--fix
]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
Expand Down
4 changes: 2 additions & 2 deletions pandas-stubs/_libs/interval.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
left: _OrderableT,
right: _OrderableT,
closed: IntervalClosedType = ...,
): ...
) -> None: ...
def __hash__(self) -> int: ...
# for __contains__, it seems that we have to separate out the 4 cases to make
# mypy happy
Expand Down Expand Up @@ -222,7 +222,7 @@ class IntervalTree(IntervalMixin):
right: np.ndarray,
closed: IntervalClosedType = ...,
leaf_size: int = ...,
): ...
) -> None: ...
def get_indexer(self, target) -> npt.NDArray[np.intp]: ...
def get_indexer_non_unique(
self, target
Expand Down
18 changes: 10 additions & 8 deletions pandas-stubs/_libs/tslibs/offsets.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class RelativeDeltaOffset(BaseOffset):
class BusinessMixin(SingleConstructorOffset):
def __init__(
self, n: int = ..., normalize: bool = ..., offset: timedelta = ...
): ...
) -> None: ...

class BusinessDay(BusinessMixin): ...

Expand All @@ -135,15 +135,17 @@ class BusinessHour(BusinessMixin):
start: str | time | Collection[str | time] = ...,
end: str | time | Collection[str | time] = ...,
offset: timedelta = ...,
): ...
) -> None: ...

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

class YearOffset(SingleConstructorOffset):
def __init__(
self, n: int = ..., normalize: bool = ..., month: int | None = ...
): ...
) -> None: ...

class BYearEnd(YearOffset): ...
class BYearBegin(YearOffset): ...
Expand Down Expand Up @@ -206,7 +208,7 @@ class _CustomBusinessMonth(BusinessMixin):
normalize: bool = ...,
offset: timedelta = ...,
holidays: list | None = ...,
): ...
) -> None: ...

class CustomBusinessDay(BusinessDay):
def __init__(
Expand All @@ -215,7 +217,7 @@ class CustomBusinessDay(BusinessDay):
normalize: bool = ...,
holidays: list = ...,
calendar: AbstractHolidayCalendar | np.busdaycalendar = ...,
): ...
) -> None: ...

class CustomBusinessHour(BusinessHour):
def __init__(
Expand All @@ -226,7 +228,7 @@ class CustomBusinessHour(BusinessHour):
end: str | time | Collection[str | time] = ...,
offset: timedelta = ...,
holidays: list | None = ...,
): ...
) -> None: ...

class CustomBusinessMonthEnd(_CustomBusinessMonth): ...
class CustomBusinessMonthBegin(_CustomBusinessMonth): ...
Expand Down Expand Up @@ -256,7 +258,7 @@ class DateOffset(RelativeDeltaOffset):
second: int = ...,
microsecond: int = ...,
nanosecond: int = ...,
): ...
) -> None: ...

BDay = BusinessDay
BMonthEnd = BusinessMonthEnd
Expand Down
3 changes: 1 addition & 2 deletions pandas-stubs/_libs/tslibs/period.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ from pandas.core.series import (
from typing_extensions import TypeAlias

from pandas._libs.tslibs import NaTType
from pandas._libs.tslibs.offsets import BaseOffset
from pandas._libs.tslibs.timestamps import Timestamp
from pandas._typing import npt

class IncompatibleFrequency(ValueError): ...

from pandas._libs.tslibs.offsets import BaseOffset

_PeriodAddSub: TypeAlias = (
Timedelta | datetime.timedelta | np.timedelta64 | np.int64 | int | BaseOffset
)
Expand Down
16 changes: 8 additions & 8 deletions pandas-stubs/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ DtypeBackend: TypeAlias = Literal["pyarrow", "numpy_nullable"]

BooleanDtypeArg: TypeAlias = (
# Builtin bool type and its string alias
type[bool] # noqa: Y030
type[bool] # noqa: PYI030
| Literal["bool"]
# Pandas nullable boolean type and its string alias
| pd.BooleanDtype
Expand All @@ -105,7 +105,7 @@ BooleanDtypeArg: TypeAlias = (
)
IntDtypeArg: TypeAlias = (
# Builtin integer type and its string alias
type[int] # noqa: Y030
type[int] # noqa: PYI030
| Literal["int"]
# Pandas nullable integer types and their string aliases
| pd.Int8Dtype
Expand Down Expand Up @@ -137,7 +137,7 @@ IntDtypeArg: TypeAlias = (
)
UIntDtypeArg: TypeAlias = (
# Pandas nullable unsigned integer types and their string aliases
pd.UInt8Dtype # noqa: Y030
pd.UInt8Dtype # noqa: PYI030
| pd.UInt16Dtype
| pd.UInt32Dtype
| pd.UInt64Dtype
Expand Down Expand Up @@ -166,7 +166,7 @@ UIntDtypeArg: TypeAlias = (
)
FloatDtypeArg: TypeAlias = (
# Builtin float type and its string alias
type[float] # noqa: Y030
type[float] # noqa: PYI030
| Literal["float"]
# Pandas nullable float types and their string aliases
| pd.Float32Dtype
Expand Down Expand Up @@ -197,7 +197,7 @@ FloatDtypeArg: TypeAlias = (
)
ComplexDtypeArg: TypeAlias = (
# Builtin complex type and its string alias
type[complex] # noqa: Y030
type[complex] # noqa: PYI030
| Literal["complex"]
# Numpy complex types and their aliases
# https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.csingle
Expand Down Expand Up @@ -326,7 +326,7 @@ TimestampDtypeArg: TypeAlias = Literal[

StrDtypeArg: TypeAlias = (
# Builtin str type and its string alias
type[str] # noqa: Y030
type[str] # noqa: PYI030
| Literal["str"]
# Pandas nullable string type and its string alias
| pd.StringDtype
Expand All @@ -340,7 +340,7 @@ StrDtypeArg: TypeAlias = (
)
BytesDtypeArg: TypeAlias = (
# Builtin bytes type and its string alias
type[bytes] # noqa: Y030
type[bytes] # noqa: PYI030
| Literal["bytes"]
# Numpy bytes type and its string alias
# https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.bytes_
Expand All @@ -353,7 +353,7 @@ CategoryDtypeArg: TypeAlias = CategoricalDtype | Literal["category"]

ObjectDtypeArg: TypeAlias = (
# Builtin object type and its string alias
type[object] # noqa: Y030
type[object] # noqa: PYI030
| Literal["object"]
# Numpy object type and its string alias
# https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.object_
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/computation/expr.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class PandasExprVisitor(BaseExprVisitor):
def __init__(self, env, engine, parser, preparser=...) -> None: ...

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

class Expr:
env: Scope
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/computation/pytables.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class UnaryOp(ops.UnaryOp):
class PyTablesExprVisitor(BaseExprVisitor):
const_type = ...
term_type = ...
def __init__(self, env, engine, parser, **kwargs): ...
def __init__(self, env, engine, parser, **kwargs) -> None: ...
def visit_UnaryOp(self, node, **kwargs): ...
def visit_Index(self, node, **kwargs): ...
def visit_Assign(self, node, **kwargs): ...
Expand Down
4 changes: 2 additions & 2 deletions pandas-stubs/core/dtypes/dtypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ class DatetimeTZDtype(PandasExtensionDtype):
def na_value(self) -> NaTType: ...

class PeriodDtype(PandasExtensionDtype):
def __init__(self, freq: str | BaseOffset = ...): ...
def __init__(self, freq: str | BaseOffset = ...) -> None: ...
@property
def freq(self) -> BaseOffset: ...
@property
def na_value(self) -> NaTType: ...

class IntervalDtype(PandasExtensionDtype):
def __init__(self, subtype: str | npt.DTypeLike | None = ...): ...
def __init__(self, subtype: str | npt.DTypeLike | None = ...) -> None: ...
@property
def subtype(self) -> np.dtype | None: ...
2 changes: 1 addition & 1 deletion pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ class DataFrame(NDFrame, OpsMixin):
def isetitem(
self, loc: int | Sequence[int], value: Scalar | ArrayLike | list[Any]
) -> None: ...
def __setitem__(self, key, value): ...
def __setitem__(self, key, value) -> None: ...
@overload
def query(self, expr: _str, *, inplace: Literal[True], **kwargs) -> None: ...
@overload
Expand Down
5 changes: 2 additions & 3 deletions pandas-stubs/core/generic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import numpy as np
from pandas import Index
from pandas.core.base import PandasObject
import pandas.core.indexing as indexing
from pandas.core.series import Series
import sqlalchemy.engine

from pandas._typing import (
Expand Down Expand Up @@ -286,7 +287,7 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
def take(
self, indices, axis=..., is_copy: _bool | None = ..., **kwargs
) -> NDFrame: ...
def __delitem__(self, idx: Hashable): ...
def __delitem__(self, idx: Hashable) -> None: ...
def get(self, key: object, default: Dtype | None = ...) -> Dtype: ...
def reindex_like(
self,
Expand Down Expand Up @@ -479,5 +480,3 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
) -> NDFrame: ...
def first_valid_index(self): ...
def last_valid_index(self): ...

from pandas.core.series import Series
4 changes: 2 additions & 2 deletions pandas-stubs/core/indexers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class BaseIndexer:
index_array: np.ndarray | None = ...,
window_size: int = ...,
**kwargs,
): ...
) -> None: ...
def get_window_bounds(
self,
num_values: int = ...,
Expand All @@ -33,7 +33,7 @@ class VariableOffsetWindowIndexer(BaseIndexer):
index=...,
offset=...,
**kwargs,
): ...
) -> None: ...
def get_window_bounds(
self,
num_values: int = ...,
Expand Down
16 changes: 8 additions & 8 deletions pandas-stubs/core/indexes/accessors.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ class Properties(PandasDelegate, PandasObject, NoNewAttributesMixin):

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

class _DatetimeFieldOps(
_DayLikeFieldOps[_DTFieldOpsReturnType], _MiniSeconds[_DTFieldOpsReturnType]
): ...
class PeriodIndexFieldOps(
_DayLikeFieldOps[_IntIndexType],
_PeriodProperties[DatetimeIndex, _IntIndexType, Index, DatetimeIndex, PeriodIndex],
): ...

class _DayLikeFieldOps(Generic[_DTFieldOpsReturnType]):
@property
def year(self) -> _DTFieldOpsReturnType: ...
Expand Down Expand Up @@ -89,6 +81,10 @@ class _MiniSeconds(Generic[_DTFieldOpsReturnType]):
@property
def nanosecond(self) -> _DTFieldOpsReturnType: ...

class _DatetimeFieldOps(
_DayLikeFieldOps[_DTFieldOpsReturnType], _MiniSeconds[_DTFieldOpsReturnType]
): ...

_DTBoolOpsReturnType = TypeVar("_DTBoolOpsReturnType", Series[bool], np_ndarray_bool)

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

class PeriodIndexFieldOps(
_DayLikeFieldOps[_IntIndexType],
_PeriodProperties[DatetimeIndex, _IntIndexType, Index, DatetimeIndex, PeriodIndex],
): ...
class PeriodProperties(
Properties,
_PeriodProperties[
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/indexes/datetimes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class DatetimeIndex( # type: ignore[misc]
dtype=...,
copy: bool = ...,
name=...,
): ...
) -> None: ...
def __array__(self, dtype=...) -> np.ndarray: ...
def __reduce__(self): ...
# various ignores needed for mypy, as we do want to restrict what can be used in
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/indexes/range.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class RangeIndex(_IntIndexType):
dtype=...,
copy: bool = ...,
name=...,
): ...
) -> None: ...
@classmethod
def from_range(cls, data, name=..., dtype=...): ...
def __reduce__(self): ...
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/indexes/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TimedeltaIndex( # type: ignore[misc]
dtype: Literal["<m8[ns]"] = ...,
copy: bool = ...,
name: str = ...,
): ...
) -> None: ...
# various ignores needed for mypy, as we do want to restrict what can be used in
# arithmetic for these types
@overload
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/io/formats/style.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ from pandas.io.formats.style_render import (
Subset,
)

class Styler(StylerRenderer[Styler]):
class Styler(StylerRenderer):
def __init__(
self,
data: DataFrame | Series,
Expand Down
Loading