From 560b1709bb1d25ab697a83cd198bd879f710d0ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Thu, 20 Jul 2023 10:17:40 -0400 Subject: [PATCH 1/8] Replace flake8 and pyupgrade with ruff --- .pre-commit-config.yaml | 29 +++++++------------------ pandas-stubs/_libs/tslibs/period.pyi | 3 +-- pandas-stubs/_typing.pyi | 17 +++++++++++---- pandas-stubs/core/generic.pyi | 3 +-- pandas-stubs/core/indexes/accessors.pyi | 9 +++++--- tests/test_timefuncs.py | 14 +++++------- 6 files changed, 34 insertions(+), 41 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 505da9551..79af1cfdf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,29 +10,16 @@ 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, _*.pyi:PYI030" ] - repo: https://github.com/codespell-project/codespell rev: v2.2.5 diff --git a/pandas-stubs/_libs/tslibs/period.pyi b/pandas-stubs/_libs/tslibs/period.pyi index 315030954..17352b959 100644 --- a/pandas-stubs/_libs/tslibs/period.pyi +++ b/pandas-stubs/_libs/tslibs/period.pyi @@ -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 ) diff --git a/pandas-stubs/_typing.pyi b/pandas-stubs/_typing.pyi index ac311799e..d3af36e7e 100644 --- a/pandas-stubs/_typing.pyi +++ b/pandas-stubs/_typing.pyi @@ -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] | Literal["bool"] # Pandas nullable boolean type and its string alias | pd.BooleanDtype @@ -105,7 +105,7 @@ BooleanDtypeArg: TypeAlias = ( ) IntDtypeArg: TypeAlias = ( # Builtin integer type and its string alias - type[int] # noqa: Y030 + type[int] | Literal["int"] # Pandas nullable integer types and their string aliases | pd.Int8Dtype @@ -164,9 +164,18 @@ UIntDtypeArg: TypeAlias = ( # PyArrow unsigned integer types and their string aliases | Literal["uint8[pyarrow]", "uint16[pyarrow]", "uint32[pyarrow]", "uint64[pyarrow]"] ) +StrDtypeArg: TypeAlias = ( + # Builtin str type and its string alias + type[str] + | Literal["str"] + # Pandas nullable string type and its string alias + | pd.StringDtype + | Literal["string"] +) +BytesDtypeArg: TypeAlias = type[bytes] FloatDtypeArg: TypeAlias = ( # Builtin float type and its string alias - type[float] # noqa: Y030 + type[float] | Literal["float"] # Pandas nullable float types and their string aliases | pd.Float32Dtype @@ -197,7 +206,7 @@ FloatDtypeArg: TypeAlias = ( ) ComplexDtypeArg: TypeAlias = ( # Builtin complex type and its string alias - type[complex] # noqa: Y030 + type[complex] | Literal["complex"] # Numpy complex types and their aliases # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.csingle diff --git a/pandas-stubs/core/generic.pyi b/pandas-stubs/core/generic.pyi index 58e080b68..8ab10e017 100644 --- a/pandas-stubs/core/generic.pyi +++ b/pandas-stubs/core/generic.pyi @@ -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 ( @@ -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 diff --git a/pandas-stubs/core/indexes/accessors.pyi b/pandas-stubs/core/indexes/accessors.pyi index fc249ca51..e4f2665e0 100644 --- a/pandas-stubs/core/indexes/accessors.pyi +++ b/pandas-stubs/core/indexes/accessors.pyi @@ -46,11 +46,14 @@ class Properties(PandasDelegate, PandasObject, NoNewAttributesMixin): _DTFieldOpsReturnType = TypeVar("_DTFieldOpsReturnType", Series[int], _IntIndexType) class _DatetimeFieldOps( - _DayLikeFieldOps[_DTFieldOpsReturnType], _MiniSeconds[_DTFieldOpsReturnType] + _DayLikeFieldOps[_DTFieldOpsReturnType], # noqa: F821 + _MiniSeconds[_DTFieldOpsReturnType], # noqa: F821 ): ... class PeriodIndexFieldOps( - _DayLikeFieldOps[_IntIndexType], - _PeriodProperties[DatetimeIndex, _IntIndexType, Index, DatetimeIndex, PeriodIndex], + _DayLikeFieldOps[_IntIndexType], # noqa: F821 + _PeriodProperties[ # noqa: F821 + DatetimeIndex, _IntIndexType, Index, DatetimeIndex, PeriodIndex + ], ): ... class _DayLikeFieldOps(Generic[_DTFieldOpsReturnType]): diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index e5f2a283c..ed1a0eab8 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -1,4 +1,3 @@ -# flake8: noqa: F841 from __future__ import annotations import datetime as dt @@ -6,7 +5,6 @@ TYPE_CHECKING, Any, Optional, - Union, ) import numpy as np @@ -43,11 +41,9 @@ ) if TYPE_CHECKING: - from pandas.core.series import ( - PeriodSeries, - TimedeltaSeries, - TimestampSeries, - ) + from pandas.core.series import PeriodSeries # noqa: F401 + from pandas.core.series import TimedeltaSeries # noqa: F401 + from pandas.core.series import TimestampSeries # noqa: F401 if TYPE_CHECKING: from pandas.core.indexes.base import _IntIndexType @@ -310,7 +306,7 @@ def test_to_datetime_nat() -> None: check( assert_type( pd.to_datetime("2021-03-01", errors="coerce"), - "Union[pd.Timestamp, NaTType]", + "pd.Timestamp | NaTType", ), pd.Timestamp, ) @@ -318,7 +314,7 @@ def test_to_datetime_nat() -> None: check( assert_type( pd.to_datetime("not a date", errors="coerce"), - "Union[pd.Timestamp, NaTType]", + "pd.Timestamp | NaTType", ), NaTType, ) From fff4408cee9a5312e8380babb4428aa7b8e6fbe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Thu, 20 Jul 2023 10:36:39 -0400 Subject: [PATCH 2/8] applied autofixes from ANN204 but disabled it because we have too many special methods without return types --- .pre-commit-config.yaml | 3 ++- pandas-stubs/_libs/interval.pyi | 4 ++-- pandas-stubs/_libs/tslibs/offsets.pyi | 16 ++++++++-------- pandas-stubs/core/computation/expr.pyi | 2 +- pandas-stubs/core/computation/pytables.pyi | 2 +- pandas-stubs/core/dtypes/dtypes.pyi | 4 ++-- pandas-stubs/core/frame.pyi | 2 +- pandas-stubs/core/generic.pyi | 2 +- pandas-stubs/core/indexers.pyi | 4 ++-- pandas-stubs/core/indexes/datetimes.pyi | 2 +- pandas-stubs/core/indexes/range.pyi | 2 +- pandas-stubs/core/indexes/timedeltas.pyi | 2 +- tests/extension/decimal/array.py | 2 +- 13 files changed, 24 insertions(+), 23 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 79af1cfdf..412a2747f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,7 +19,8 @@ repos: --target-version, py38, --extend-select, "PYI,UP,RUF100", --ignore, "E501,E731,F841,PYI042", - --per-file-ignores, "_*.pyi:PYI001, _*.pyi:PYI030" + --per-file-ignores, "_*.pyi:PYI001, _*.pyi:PYI030", + --fix ] - repo: https://github.com/codespell-project/codespell rev: v2.2.5 diff --git a/pandas-stubs/_libs/interval.pyi b/pandas-stubs/_libs/interval.pyi index 0dd40c964..0ad353291 100644 --- a/pandas-stubs/_libs/interval.pyi +++ b/pandas-stubs/_libs/interval.pyi @@ -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 @@ -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 diff --git a/pandas-stubs/_libs/tslibs/offsets.pyi b/pandas-stubs/_libs/tslibs/offsets.pyi index 8e29af4e3..e2f9c96a7 100644 --- a/pandas-stubs/_libs/tslibs/offsets.pyi +++ b/pandas-stubs/_libs/tslibs/offsets.pyi @@ -123,7 +123,7 @@ class RelativeDeltaOffset(BaseOffset): class BusinessMixin(SingleConstructorOffset): def __init__( self, n: int = ..., normalize: bool = ..., offset: timedelta = ... - ): ... + ) -> None: ... class BusinessDay(BusinessMixin): ... @@ -135,15 +135,15 @@ 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): ... @@ -206,7 +206,7 @@ class _CustomBusinessMonth(BusinessMixin): normalize: bool = ..., offset: timedelta = ..., holidays: list | None = ..., - ): ... + ) -> None: ... class CustomBusinessDay(BusinessDay): def __init__( @@ -215,7 +215,7 @@ class CustomBusinessDay(BusinessDay): normalize: bool = ..., holidays: list = ..., calendar: AbstractHolidayCalendar | np.busdaycalendar = ..., - ): ... + ) -> None: ... class CustomBusinessHour(BusinessHour): def __init__( @@ -226,7 +226,7 @@ class CustomBusinessHour(BusinessHour): end: str | time | Collection[str | time] = ..., offset: timedelta = ..., holidays: list | None = ..., - ): ... + ) -> None: ... class CustomBusinessMonthEnd(_CustomBusinessMonth): ... class CustomBusinessMonthBegin(_CustomBusinessMonth): ... @@ -256,7 +256,7 @@ class DateOffset(RelativeDeltaOffset): second: int = ..., microsecond: int = ..., nanosecond: int = ..., - ): ... + ) -> None: ... BDay = BusinessDay BMonthEnd = BusinessMonthEnd diff --git a/pandas-stubs/core/computation/expr.pyi b/pandas-stubs/core/computation/expr.pyi index 0eb8c9af8..d3f31c7d1 100644 --- a/pandas-stubs/core/computation/expr.pyi +++ b/pandas-stubs/core/computation/expr.pyi @@ -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 diff --git a/pandas-stubs/core/computation/pytables.pyi b/pandas-stubs/core/computation/pytables.pyi index 6acb53113..85135c934 100644 --- a/pandas-stubs/core/computation/pytables.pyi +++ b/pandas-stubs/core/computation/pytables.pyi @@ -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): ... diff --git a/pandas-stubs/core/dtypes/dtypes.pyi b/pandas-stubs/core/dtypes/dtypes.pyi index 48e42f496..7c075d8f5 100644 --- a/pandas-stubs/core/dtypes/dtypes.pyi +++ b/pandas-stubs/core/dtypes/dtypes.pyi @@ -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: ... diff --git a/pandas-stubs/core/frame.pyi b/pandas-stubs/core/frame.pyi index 906dab8e6..f9c195b18 100644 --- a/pandas-stubs/core/frame.pyi +++ b/pandas-stubs/core/frame.pyi @@ -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 diff --git a/pandas-stubs/core/generic.pyi b/pandas-stubs/core/generic.pyi index 8ab10e017..034328e1a 100644 --- a/pandas-stubs/core/generic.pyi +++ b/pandas-stubs/core/generic.pyi @@ -287,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, diff --git a/pandas-stubs/core/indexers.pyi b/pandas-stubs/core/indexers.pyi index a36a5bc31..98830f534 100644 --- a/pandas-stubs/core/indexers.pyi +++ b/pandas-stubs/core/indexers.pyi @@ -16,7 +16,7 @@ class BaseIndexer: index_array: np.ndarray | None = ..., window_size: int = ..., **kwargs, - ): ... + ) -> None: ... def get_window_bounds( self, num_values: int = ..., @@ -33,7 +33,7 @@ class VariableOffsetWindowIndexer(BaseIndexer): index=..., offset=..., **kwargs, - ): ... + ) -> None: ... def get_window_bounds( self, num_values: int = ..., diff --git a/pandas-stubs/core/indexes/datetimes.pyi b/pandas-stubs/core/indexes/datetimes.pyi index 615cb098e..baa06efdf 100644 --- a/pandas-stubs/core/indexes/datetimes.pyi +++ b/pandas-stubs/core/indexes/datetimes.pyi @@ -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 diff --git a/pandas-stubs/core/indexes/range.pyi b/pandas-stubs/core/indexes/range.pyi index 79bd4471e..3166fc7d2 100644 --- a/pandas-stubs/core/indexes/range.pyi +++ b/pandas-stubs/core/indexes/range.pyi @@ -33,7 +33,7 @@ class RangeIndex(_IntIndexType): dtype=..., copy: bool = ..., name=..., - ): ... + ) -> None: ... @classmethod def from_range(cls, data, name=..., dtype=...): ... def __reduce__(self): ... diff --git a/pandas-stubs/core/indexes/timedeltas.pyi b/pandas-stubs/core/indexes/timedeltas.pyi index 9a58bdc0d..e4b7fd02b 100644 --- a/pandas-stubs/core/indexes/timedeltas.pyi +++ b/pandas-stubs/core/indexes/timedeltas.pyi @@ -46,7 +46,7 @@ class TimedeltaIndex( # type: ignore[misc] dtype: Literal[" None: ... # various ignores needed for mypy, as we do want to restrict what can be used in # arithmetic for these types @overload diff --git a/tests/extension/decimal/array.py b/tests/extension/decimal/array.py index 8fac43ac5..f29e73e58 100644 --- a/tests/extension/decimal/array.py +++ b/tests/extension/decimal/array.py @@ -200,7 +200,7 @@ def astype(self, dtype, copy=True): return super().astype(dtype, copy=copy) - def __setitem__(self, key, value): + def __setitem__(self, key, value) -> None: if is_list_like(value): if is_scalar(key): raise ValueError("setting an array element with a sequence.") From 90dfb81500e90afc20ad779bb30ba0a61ca70cab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Thu, 20 Jul 2023 10:38:13 -0400 Subject: [PATCH 3/8] black --- pandas-stubs/_libs/tslibs/offsets.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas-stubs/_libs/tslibs/offsets.pyi b/pandas-stubs/_libs/tslibs/offsets.pyi index e2f9c96a7..2bed61cf2 100644 --- a/pandas-stubs/_libs/tslibs/offsets.pyi +++ b/pandas-stubs/_libs/tslibs/offsets.pyi @@ -138,7 +138,9 @@ class BusinessHour(BusinessMixin): ) -> None: ... class WeekOfMonthMixin(SingleConstructorOffset): - def __init__(self, n: int = ..., weekday: Literal[0, 1, 2, 3, 4, 5, 6] = ...) -> None: ... + def __init__( + self, n: int = ..., weekday: Literal[0, 1, 2, 3, 4, 5, 6] = ... + ) -> None: ... class YearOffset(SingleConstructorOffset): def __init__( From a64d4e597a70fd7ab14e1a92464da7f624535264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Thu, 20 Jul 2023 10:44:04 -0400 Subject: [PATCH 4/8] Use Self --- pandas-stubs/io/formats/style.pyi | 2 +- pandas-stubs/io/formats/style_render.pyi | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/pandas-stubs/io/formats/style.pyi b/pandas-stubs/io/formats/style.pyi index 770df865e..95dfcaf6f 100644 --- a/pandas-stubs/io/formats/style.pyi +++ b/pandas-stubs/io/formats/style.pyi @@ -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, diff --git a/pandas-stubs/io/formats/style_render.pyi b/pandas-stubs/io/formats/style_render.pyi index dd33670be..762eea0da 100644 --- a/pandas-stubs/io/formats/style_render.pyi +++ b/pandas-stubs/io/formats/style_render.pyi @@ -4,16 +4,17 @@ from collections.abc import ( ) from typing import ( Any, - Generic, Literal, TypedDict, - TypeVar, ) import jinja2 from pandas import Index from pandas.core.indexing import _IndexSlice -from typing_extensions import TypeAlias +from typing_extensions import ( + Self, + TypeAlias, +) from pandas._typing import ( Axis, @@ -44,9 +45,7 @@ class StyleExportDict(TypedDict, total=False): CSSStyles: TypeAlias = list[CSSDict] Subset: TypeAlias = _IndexSlice | slice | tuple[slice, ...] | list[HashableT] | Index -_StylerT = TypeVar("_StylerT", bound=StylerRenderer) - -class StylerRenderer(Generic[_StylerT]): +class StylerRenderer: loader: jinja2.loaders.PackageLoader env: jinja2.environment.Environment template_html: jinja2.environment.Template @@ -63,7 +62,7 @@ class StylerRenderer(Generic[_StylerT]): thousands: str | None = ..., escape: str | None = ..., hyperlinks: Literal["html", "latex"] | None = ..., - ) -> _StylerT: ... + ) -> Self: ... def format_index( self, formatter: ExtFormatter | None = ..., @@ -75,10 +74,10 @@ class StylerRenderer(Generic[_StylerT]): thousands: str | None = ..., escape: str | None = ..., hyperlinks: Literal["html", "latex"] | None = ..., - ) -> _StylerT: ... + ) -> Self: ... def relabel_index( self, labels: Sequence[str] | Index, axis: Axis = ..., level: Level | list[Level] | None = ..., - ) -> _StylerT: ... + ) -> Self: ... From 515ae35143feb82f0ffcc1c6183de9d10a8a48d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Thu, 20 Jul 2023 11:02:14 -0400 Subject: [PATCH 5/8] Allow mypy to use incremental runs --- scripts/test/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test/run.py b/scripts/test/run.py index 167199642..e2480e2dc 100644 --- a/scripts/test/run.py +++ b/scripts/test/run.py @@ -6,7 +6,7 @@ def mypy_src(): - cmd = ["mypy", "pandas-stubs", "tests", "--no-incremental"] + cmd = ["mypy", "pandas-stubs", "tests"] subprocess.run(cmd, check=True) From 6c185dda7b3ec0707ae7b4e0338bfc55f2f5158f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Thu, 20 Jul 2023 11:35:32 -0400 Subject: [PATCH 6/8] Revert "Allow mypy to use incremental runs" This reverts commit b3673c37fa20fcdf337ff679ccd15bdd4f2c3951. --- scripts/test/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test/run.py b/scripts/test/run.py index e2480e2dc..167199642 100644 --- a/scripts/test/run.py +++ b/scripts/test/run.py @@ -6,7 +6,7 @@ def mypy_src(): - cmd = ["mypy", "pandas-stubs", "tests"] + cmd = ["mypy", "pandas-stubs", "tests", "--no-incremental"] subprocess.run(cmd, check=True) From 7a6a4e1eb69f33353e4bc5ead36eec0d1a4e2505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Thu, 20 Jul 2023 11:41:25 -0400 Subject: [PATCH 7/8] line-based ignores for PYI030 --- .pre-commit-config.yaml | 2 +- pandas-stubs/_typing.pyi | 10 +++++----- pandas-stubs/core/indexes/accessors.pyi | 19 ++++++++----------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 412a2747f..cc0e9aaa0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,7 +19,7 @@ repos: --target-version, py38, --extend-select, "PYI,UP,RUF100", --ignore, "E501,E731,F841,PYI042", - --per-file-ignores, "_*.pyi:PYI001, _*.pyi:PYI030", + --per-file-ignores, "_*.pyi:PYI001", --fix ] - repo: https://github.com/codespell-project/codespell diff --git a/pandas-stubs/_typing.pyi b/pandas-stubs/_typing.pyi index d3af36e7e..b7beeb408 100644 --- a/pandas-stubs/_typing.pyi +++ b/pandas-stubs/_typing.pyi @@ -91,7 +91,7 @@ DtypeBackend: TypeAlias = Literal["pyarrow", "numpy_nullable"] BooleanDtypeArg: TypeAlias = ( # Builtin bool type and its string alias - type[bool] + type[bool] # noqa: PYI030 | Literal["bool"] # Pandas nullable boolean type and its string alias | pd.BooleanDtype @@ -105,7 +105,7 @@ BooleanDtypeArg: TypeAlias = ( ) IntDtypeArg: TypeAlias = ( # Builtin integer type and its string alias - type[int] + type[int] # noqa: PYI030 | Literal["int"] # Pandas nullable integer types and their string aliases | pd.Int8Dtype @@ -166,7 +166,7 @@ UIntDtypeArg: TypeAlias = ( ) StrDtypeArg: TypeAlias = ( # Builtin str type and its string alias - type[str] + type[str] # noqa: PYI030 | Literal["str"] # Pandas nullable string type and its string alias | pd.StringDtype @@ -175,7 +175,7 @@ StrDtypeArg: TypeAlias = ( BytesDtypeArg: TypeAlias = type[bytes] FloatDtypeArg: TypeAlias = ( # Builtin float type and its string alias - type[float] + type[float] # noqa: PYI030 | Literal["float"] # Pandas nullable float types and their string aliases | pd.Float32Dtype @@ -206,7 +206,7 @@ FloatDtypeArg: TypeAlias = ( ) ComplexDtypeArg: TypeAlias = ( # Builtin complex type and its string alias - type[complex] + type[complex] # noqa: PYI030 | Literal["complex"] # Numpy complex types and their aliases # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.csingle diff --git a/pandas-stubs/core/indexes/accessors.pyi b/pandas-stubs/core/indexes/accessors.pyi index e4f2665e0..699a74a30 100644 --- a/pandas-stubs/core/indexes/accessors.pyi +++ b/pandas-stubs/core/indexes/accessors.pyi @@ -45,17 +45,6 @@ class Properties(PandasDelegate, PandasObject, NoNewAttributesMixin): _DTFieldOpsReturnType = TypeVar("_DTFieldOpsReturnType", Series[int], _IntIndexType) -class _DatetimeFieldOps( - _DayLikeFieldOps[_DTFieldOpsReturnType], # noqa: F821 - _MiniSeconds[_DTFieldOpsReturnType], # noqa: F821 -): ... -class PeriodIndexFieldOps( - _DayLikeFieldOps[_IntIndexType], # noqa: F821 - _PeriodProperties[ # noqa: F821 - DatetimeIndex, _IntIndexType, Index, DatetimeIndex, PeriodIndex - ], -): ... - class _DayLikeFieldOps(Generic[_DTFieldOpsReturnType]): @property def year(self) -> _DTFieldOpsReturnType: ... @@ -92,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]): @@ -341,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[ From 4a5392c736efa01f63b19b6973838ac6c46fe8e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Tue, 25 Jul 2023 14:28:49 -0400 Subject: [PATCH 8/8] fix merge --- pandas-stubs/_typing.pyi | 17 ++++------------- tests/test_series.py | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/pandas-stubs/_typing.pyi b/pandas-stubs/_typing.pyi index b7beeb408..27548758f 100644 --- a/pandas-stubs/_typing.pyi +++ b/pandas-stubs/_typing.pyi @@ -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 @@ -164,15 +164,6 @@ UIntDtypeArg: TypeAlias = ( # PyArrow unsigned integer types and their string aliases | Literal["uint8[pyarrow]", "uint16[pyarrow]", "uint32[pyarrow]", "uint64[pyarrow]"] ) -StrDtypeArg: TypeAlias = ( - # Builtin str type and its string alias - type[str] # noqa: PYI030 - | Literal["str"] - # Pandas nullable string type and its string alias - | pd.StringDtype - | Literal["string"] -) -BytesDtypeArg: TypeAlias = type[bytes] FloatDtypeArg: TypeAlias = ( # Builtin float type and its string alias type[float] # noqa: PYI030 @@ -335,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 @@ -349,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_ @@ -362,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_ diff --git a/tests/test_series.py b/tests/test_series.py index 055d16c0d..88c9f4854 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -2568,17 +2568,17 @@ def test_all_astype_args_tested() -> None: } TESTED_ASTYPE_ARGS: list[tuple[Any, type]] = ( ASTYPE_BOOL_ARGS - + ASTYPE_INT_ARGS # noqa: W503 - + ASTYPE_UINT_ARGS # noqa: W503 - + ASTYPE_FLOAT_ARGS # noqa: W503 - + ASTYPE_COMPLEX_ARGS # noqa: W503 - + ASTYPE_TIMEDELTA_ARGS # noqa: W503 - + ASTYPE_TIMESTAMP_ARGS # noqa: W503 - + ASTYPE_BYTES_ARGS # noqa: W503 - + ASTYPE_STRING_ARGS # noqa: W503 - + ASTYPE_CATEGORICAL_ARGS # noqa: W503 - + ASTYPE_OBJECT_ARGS # noqa: W503 - + ASTYPE_VOID_ARGS # noqa: W503 + + ASTYPE_INT_ARGS + + ASTYPE_UINT_ARGS + + ASTYPE_FLOAT_ARGS + + ASTYPE_COMPLEX_ARGS + + ASTYPE_TIMEDELTA_ARGS + + ASTYPE_TIMESTAMP_ARGS + + ASTYPE_BYTES_ARGS + + ASTYPE_STRING_ARGS + + ASTYPE_CATEGORICAL_ARGS + + ASTYPE_OBJECT_ARGS + + ASTYPE_VOID_ARGS ) TESTED_ALIASES: set[str] = {