From ecda4010a55c68286c501532973787b018fd82ca Mon Sep 17 00:00:00 2001 From: cmp0xff Date: Thu, 23 Oct 2025 23:25:54 +0200 Subject: [PATCH 1/3] classify ann --- pandas-stubs/_testing/__init__.pyi | 11 ---- pandas-stubs/core/algorithms.pyi | 7 ++- pandas-stubs/core/groupby/groupby.pyi | 2 +- pandas-stubs/core/groupby/ops.pyi | 3 - .../core/interchange/dataframe_protocol.pyi | 8 ++- pandas-stubs/core/resample.pyi | 2 +- pandas-stubs/core/reshape/util.pyi | 1 - pandas-stubs/errors/__init__.pyi | 4 +- pyproject.toml | 56 ++++++++++++++++++- 9 files changed, 68 insertions(+), 26 deletions(-) delete mode 100644 pandas-stubs/core/reshape/util.pyi diff --git a/pandas-stubs/_testing/__init__.pyi b/pandas-stubs/_testing/__init__.pyi index a8aae1527..81969b55e 100644 --- a/pandas-stubs/_testing/__init__.pyi +++ b/pandas-stubs/_testing/__init__.pyi @@ -92,16 +92,6 @@ def assert_timedelta_array_equal( obj: str = "TimedeltaArray", check_freq: bool = True, ) -> None: ... -def assert_numpy_array_equal( - left, - right, - strict_nan: bool = False, - check_dtype: bool | Literal["equiv"] = True, - err_msg: str | None = None, - check_same: Literal["copy", "same"] | None = None, - obj: str = "numpy array", - index_values: Index | np.ndarray | None = None, -) -> None: ... def assert_extension_array_equal( left: ExtensionArray, right: ExtensionArray, @@ -173,7 +163,6 @@ def assert_frame_equal( atol: float = 1e-8, obj: str = "DataFrame", ) -> None: ... -def assert_equal(left, right, **kwargs: Any) -> None: ... def assert_sp_array_equal(left: SparseArray, right: SparseArray) -> None: ... def assert_contains_all(iterable: Iterable[T], dic: Container[T]) -> None: ... def assert_copy(iter1: Iterable[T], iter2: Iterable[T], **eql_kwargs: Any) -> None: ... diff --git a/pandas-stubs/core/algorithms.pyi b/pandas-stubs/core/algorithms.pyi index a89c4d829..5174218c6 100644 --- a/pandas-stubs/core/algorithms.pyi +++ b/pandas-stubs/core/algorithms.pyi @@ -1,4 +1,5 @@ from typing import ( + Any, Literal, overload, ) @@ -72,9 +73,9 @@ def value_counts( dropna: bool = True, ) -> Series: ... def take( - arr, + arr: np.ndarray | ExtensionArray | Index | Series, indices: TakeIndexer, axis: Literal[0, 1] = 0, allow_fill: bool = False, - fill_value=None, -): ... + fill_value: Any = None, +) -> np_1darray | ExtensionArray: ... diff --git a/pandas-stubs/core/groupby/groupby.pyi b/pandas-stubs/core/groupby/groupby.pyi index 150a6fa7a..c5bc50110 100644 --- a/pandas-stubs/core/groupby/groupby.pyi +++ b/pandas-stubs/core/groupby/groupby.pyi @@ -302,7 +302,7 @@ class GroupBy(BaseGroupBy[NDFrameT]): periods: int | Sequence[int] = 1, freq: Frequency | None = ..., axis: Axis | _NoDefaultDoNotUse = 0, - fill_value=..., + fill_value: Scalar | None = None, suffix: str | None = ..., ) -> NDFrameT: ... @final diff --git a/pandas-stubs/core/groupby/ops.pyi b/pandas-stubs/core/groupby/ops.pyi index 2f2665a01..740eeb760 100644 --- a/pandas-stubs/core/groupby/ops.pyi +++ b/pandas-stubs/core/groupby/ops.pyi @@ -39,9 +39,6 @@ class BaseGrouper: def get_iterator( self, data: NDFrameT, axis: AxisInt = ... ) -> Iterator[tuple[Hashable, NDFrameT]]: ... - @final - @cache_readonly - def group_keys_seq(self): ... @cache_readonly def indices(self) -> dict[Hashable, npt.NDArray[np.intp]]: ... @final diff --git a/pandas-stubs/core/interchange/dataframe_protocol.pyi b/pandas-stubs/core/interchange/dataframe_protocol.pyi index a29c573cc..94595ea1f 100644 --- a/pandas-stubs/core/interchange/dataframe_protocol.pyi +++ b/pandas-stubs/core/interchange/dataframe_protocol.pyi @@ -14,6 +14,8 @@ from typing import ( cast, ) +from typing_extensions import Self + class DlpackDeviceType(enum.IntEnum): CPU = cast(int, ...) CUDA = cast(int, ...) @@ -58,7 +60,7 @@ class Buffer(ABC, metaclass=abc.ABCMeta): @abstractmethod def ptr(self) -> int: ... @abstractmethod - def __dlpack__(self): ... + def __dlpack__(self) -> Any: ... @abstractmethod def __dlpack_device__(self) -> tuple[DlpackDeviceType, int | None]: ... @@ -94,7 +96,9 @@ class Column(ABC, metaclass=abc.ABCMeta): class DataFrame(ABC, metaclass=abc.ABCMeta): version: int @abstractmethod - def __dataframe__(self, nan_as_null: bool = ..., allow_copy: bool = ...): ... + def __dataframe__( + self, nan_as_null: bool = ..., allow_copy: bool = ... + ) -> Self: ... @property @abstractmethod def metadata(self) -> dict[str, Any]: ... diff --git a/pandas-stubs/core/resample.pyi b/pandas-stubs/core/resample.pyi index 850db0032..aae5eb340 100644 --- a/pandas-stubs/core/resample.pyi +++ b/pandas-stubs/core/resample.pyi @@ -175,7 +175,7 @@ class Resampler(BaseGroupBy[NDFrameT]): # attributes via setattr class _GroupByMixin(Resampler[NDFrameT]): key: str | list[str] | None - def __getitem__(self, key) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] + def __getitem__(self, key: Hashable) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] class DatetimeIndexResampler(Resampler[NDFrameT]): ... diff --git a/pandas-stubs/core/reshape/util.pyi b/pandas-stubs/core/reshape/util.pyi deleted file mode 100644 index 4ce584421..000000000 --- a/pandas-stubs/core/reshape/util.pyi +++ /dev/null @@ -1 +0,0 @@ -def cartesian_product(X): ... diff --git a/pandas-stubs/errors/__init__.pyi b/pandas-stubs/errors/__init__.pyi index 55c2b72ac..0b2d13369 100644 --- a/pandas-stubs/errors/__init__.pyi +++ b/pandas-stubs/errors/__init__.pyi @@ -20,7 +20,7 @@ class MergeError(ValueError): ... class AccessorRegistrationWarning(Warning): ... class AbstractMethodError(NotImplementedError): - def __init__(self, class_instance, methodtype: str = ...) -> None: ... + def __init__(self, class_instance: type, methodtype: str = ...) -> None: ... class NumbaUtilError(Exception): ... class DuplicateLabelError(ValueError): ... @@ -34,7 +34,7 @@ class IndexingError(Exception): ... class PyperclipException(RuntimeError): ... class PyperclipWindowsException(PyperclipException): - def __init__(self, message) -> None: ... + def __init__(self, message: str) -> None: ... class CSSWarning(UserWarning): ... class PossibleDataLossError(Exception): ... diff --git a/pyproject.toml b/pyproject.toml index f1223bc0b..c93384dd0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -200,8 +200,60 @@ ignore = [ "A004", # https://docs.astral.sh/ruff/rules/builtin-import-shadowing/ "PYI001", # https://docs.astral.sh/ruff/rules/unprefixed-type-param/ "PYI042", # https://docs.astral.sh/ruff/rules/snake-case-type-alias/ - "ERA001", "ANN001", "ANN201", "ANN204", "ANN206", "ANN401", "PLR0402", "PLC0105" - ] + "ERA001", "ANN401", "PLR0402", "PLC0105" +] +"*range.pyi" = [ + # TODO: remove when pandas-dev/pandas-stubs#1442 is resolved + "ANN001", "ANN201", "ANN204", "ANN206", +] +"*category.pyi" = [ + # TODO: remove when pandas-dev/pandas-stubs#1443 is resolved + "ANN001", "ANN201", "ANN204", "ANN206", +] +"*series.pyi" = [ + # TODO: remove when pandas-dev/pandas-stubs#1444 is resolved + "ANN001", "ANN201", "ANN204", "ANN206", +] +"*frame.pyi" = [ + # TODO: remove when pandas-dev/pandas-stubs#1446 is resolved + "ANN001", "ANN201", "ANN204", "ANN206", +] +"*index*" = [ + # TODO: remove when indexes are fully typed + "ANN001", "ANN201", "ANN204", "ANN206", +] +"*computation*" = [ + # TODO: remove when computations are fully typed + "ANN001", "ANN201", "ANN204", "ANN206", +] +"*plotting*" = [ + # TODO: remove when plottings are fully typed + "ANN001", "ANN201", "ANN204", "ANN206", +] +"*io*" = [ + # TODO: remove when io is fully typed + "ANN001", "ANN201", "ANN204", "ANN206", +] +"*window*" = [ + # TODO: remove when window is fully typed + "ANN001", "ANN201", "ANN204", "ANN206", +] +"*generic.pyi" = [ + # TODO: remove when generic.pyi is fully typed + "ANN001", "ANN201", "ANN204", "ANN206", +] +"*array*" = [ + # TODO: remove when array is fully typed + "ANN001", "ANN201", "ANN204", "ANN206", +] +"*_libs*" = [ + # TODO: remove when _libs is fully typed + "ANN001", "ANN201", "ANN204", "ANN206", +] +"*base.pyi" = [ + # TODO: remove when base.pyi's are fully typed + "ANN001", "ANN201", "ANN204", "ANN206", +] "scripts/*" = [ # The following rules are ignored permanently for good reasons "EM", # https://docs.astral.sh/ruff/rules/#flake8-errmsg-em From 65f1503e7918f0d0793a58d53a6f49b2296467c2 Mon Sep 17 00:00:00 2001 From: cmp0xff Date: Fri, 24 Oct 2025 10:05:31 +0200 Subject: [PATCH 2/3] mypy --- pandas-stubs/core/resample.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas-stubs/core/resample.pyi b/pandas-stubs/core/resample.pyi index aae5eb340..e823e5243 100644 --- a/pandas-stubs/core/resample.pyi +++ b/pandas-stubs/core/resample.pyi @@ -175,7 +175,7 @@ class Resampler(BaseGroupBy[NDFrameT]): # attributes via setattr class _GroupByMixin(Resampler[NDFrameT]): key: str | list[str] | None - def __getitem__(self, key: Hashable) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] + def __getitem__(self, key: str | list[str] | None) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] class DatetimeIndexResampler(Resampler[NDFrameT]): ... From ec57e2171444b06fb88c5cba361d27a6a3bc718e Mon Sep 17 00:00:00 2001 From: cmp0xff Date: Sat, 25 Oct 2025 23:56:44 +0200 Subject: [PATCH 3/3] fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1445#discussion_r2462952840 --- tests/extension/decimal/array.py | 34 ++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/tests/extension/decimal/array.py b/tests/extension/decimal/array.py index c77436d2b..3a4d71047 100644 --- a/tests/extension/decimal/array.py +++ b/tests/extension/decimal/array.py @@ -4,6 +4,8 @@ from collections.abc import ( Callable, Iterable, + MutableSequence, + Sequence, ) import decimal import numbers @@ -37,6 +39,7 @@ from pandas._typing import ( ArrayLike, AstypeArg, + ListLike, ScalarIndexer, SequenceIndexer, SequenceNotStr, @@ -91,7 +94,7 @@ class DecimalArray(OpsMixin, ExtensionScalarOpsMixin, ExtensionArray): def __init__( self, - values: list[decimal.Decimal | float] | np.ndarray, + values: MutableSequence[decimal._DecimalNew] | np.ndarray | ExtensionArray, dtype: DecimalDtype | None = None, copy: bool = False, context: decimal.Context | None = None, @@ -123,7 +126,7 @@ def dtype(self) -> DecimalDtype: @classmethod def _from_sequence( cls, - scalars: list[decimal.Decimal | float] | np.ndarray, + scalars: list[decimal._DecimalNew] | np.ndarray | ExtensionArray, dtype: DecimalDtype | None = None, copy: bool = False, ) -> Self: @@ -140,7 +143,9 @@ def _from_sequence_of_strings( @classmethod def _from_factorized( - cls, values: list[decimal.Decimal | float] | np.ndarray, original: Any + cls, + values: list[decimal._DecimalNew] | np.ndarray | ExtensionArray, + original: Any, ) -> Self: return cls(values) @@ -186,7 +191,7 @@ def reconstruct( x: ( decimal.Decimal | numbers.Number - | list[decimal.Decimal | float] + | list[decimal._DecimalNew] | np.ndarray ), ) -> decimal.Decimal | numbers.Number | DecimalArray: @@ -240,21 +245,24 @@ def astype(self, dtype, copy=True): return super().astype(dtype, copy=copy) - def __setitem__(self, key: object, value: decimal._DecimalNew) -> None: + def __setitem__( + self, + key: int | slice[Any, Any, Any] | ListLike, + value: decimal._DecimalNew | Sequence[decimal._DecimalNew], + ) -> None: if is_list_like(value): + assert isinstance(value, Iterable) if is_scalar(key): raise ValueError("setting an array element with a sequence.") - value = [ # type: ignore[assignment] - decimal.Decimal(v) # type: ignore[arg-type] - for v in value # type: ignore[union-attr] # pyright: ignore[reportAssignmentType,reportGeneralTypeIssues] + value = [ + decimal.Decimal(v) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] + for v in value ] else: - value = decimal.Decimal(value) + value = decimal.Decimal(value) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] - key = check_array_indexer( # type: ignore[call-overload] - self, key # pyright: ignore[reportArgumentType,reportCallIssue] - ) - self._data[key] = value # type: ignore[call-overload] # pyright: ignore[reportArgumentType,reportCallIssue] + key = check_array_indexer(self, key) + self._data[key] = value def __len__(self) -> int: return len(self._data)