Skip to content
Open
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
11 changes: 0 additions & 11 deletions pandas-stubs/_testing/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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: ...
Expand Down
7 changes: 4 additions & 3 deletions pandas-stubs/core/algorithms.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import (
Any,
Literal,
overload,
)
Expand Down Expand Up @@ -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: ...
2 changes: 1 addition & 1 deletion pandas-stubs/core/groupby/groupby.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions pandas-stubs/core/groupby/ops.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions pandas-stubs/core/interchange/dataframe_protocol.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ from typing import (
cast,
)

from typing_extensions import Self

class DlpackDeviceType(enum.IntEnum):
CPU = cast(int, ...)
CUDA = cast(int, ...)
Expand Down Expand Up @@ -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]: ...

Expand Down Expand Up @@ -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]: ...
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/resample.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: str | list[str] | None) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]

class DatetimeIndexResampler(Resampler[NDFrameT]): ...

Expand Down
1 change: 0 additions & 1 deletion pandas-stubs/core/reshape/util.pyi

This file was deleted.

4 changes: 2 additions & 2 deletions pandas-stubs/errors/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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): ...
Expand All @@ -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): ...
Expand Down
56 changes: 54 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,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", "PLR0402",
]
"ERA001", "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
Expand Down
34 changes: 21 additions & 13 deletions tests/extension/decimal/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from collections.abc import (
Callable,
Iterable,
MutableSequence,
Sequence,
)
import decimal
import numbers
Expand Down Expand Up @@ -37,6 +39,7 @@
from pandas._typing import (
ArrayLike,
AstypeArg,
ListLike,
ScalarIndexer,
SequenceIndexer,
SequenceNotStr,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down