Skip to content

Commit 89343dc

Browse files
authored
feat(ruff): comply to ANN202, 002, TRY, PT, BLE (#1417)
* refactor(ruff): ANN002 * refactor(ruff): TRY, PT, BLE * refactor(ruff): ANN202 * fix: mypy * fix: pytest * feat: put back __array__ * fix(ruff): PT028 * fix(ruff): TRY003 * fix: reduce Protocol * fix: missing __array__ * refactor: simplify typing * Revert "refactor: simplify typing" This reverts commit 6f82178.
1 parent 409ca56 commit 89343dc

File tree

22 files changed

+108
-96
lines changed

22 files changed

+108
-96
lines changed

pandas-stubs/_testing/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def assert_frame_equal(
176176
def assert_equal(left, right, **kwargs: Any) -> None: ...
177177
def assert_sp_array_equal(left: SparseArray, right: SparseArray) -> None: ...
178178
def assert_contains_all(iterable: Iterable[T], dic: Container[T]) -> None: ...
179-
def assert_copy(iter1: Iterable[T], iter2: Iterable[T], **eql_kwargs) -> None: ...
179+
def assert_copy(iter1: Iterable[T], iter2: Iterable[T], **eql_kwargs: Any) -> None: ...
180180
@contextmanager
181181
def assert_produces_warning(
182182
expected_warning: (

pandas-stubs/core/arrays/base.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ from pandas._typing import (
2121
from pandas.core.dtypes.dtypes import ExtensionDtype as ExtensionDtype
2222

2323
class ExtensionArray:
24+
def __array_ufunc__(
25+
self, ufunc: np.ufunc, method: str, *inputs: Any, **kwargs: Any
26+
) -> Any: ...
2427
@overload
2528
def __getitem__(self, item: ScalarIndexer) -> Any: ...
2629
@overload

pandas-stubs/core/arrays/boolean.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class BooleanArray(BaseMaskedArray):
2020
) -> None: ...
2121
@property
2222
def dtype(self): ...
23-
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs: Any): ...
2423
def __setitem__(self, key, value) -> None: ...
2524
def astype(self, dtype, copy: bool = True): ...
2625
def any(self, *, skipna: bool = ..., **kwargs: Any): ...

pandas-stubs/core/arrays/categorical.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ from pandas._typing import (
1919
ArrayLike,
2020
Dtype,
2121
ListLike,
22+
NpDtype,
2223
Ordered,
2324
PositionalIndexerTuple,
2425
Scalar,
@@ -89,8 +90,9 @@ class Categorical(ExtensionArray):
8990
@property
9091
def shape(self): ...
9192
def shift(self, periods=1, fill_value=...): ...
92-
def __array__(self, dtype=...) -> np_1darray: ...
93-
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs: Any): ...
93+
def __array__(
94+
self, dtype: NpDtype | None = None, copy: bool | None = None
95+
) -> np_1darray: ...
9496
@property
9597
def T(self): ...
9698
@property
@@ -112,8 +114,6 @@ class Categorical(ExtensionArray):
112114
def take(
113115
self, indexer: TakeIndexer, *, allow_fill: bool = ..., fill_value=...
114116
) -> Categorical: ...
115-
def __len__(self) -> int: ...
116-
def __iter__(self): ...
117117
def __contains__(self, key) -> bool: ...
118118
@overload
119119
def __getitem__(self, key: ScalarIndexer) -> Any: ...

pandas-stubs/core/arrays/datetimelike.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ from pandas._libs import (
1818
)
1919
from pandas._typing import (
2020
DatetimeLikeScalar,
21+
NpDtype,
2122
PositionalIndexerTuple,
2223
ScalarIndexer,
2324
SequenceIndexer,
2425
TimeAmbiguous,
2526
TimeNonexistent,
2627
TimeUnit,
28+
np_1darray,
2729
)
2830

2931
DTScalarOrNaT: TypeAlias = DatetimeLikeScalar | NaTType
@@ -66,10 +68,11 @@ class DatetimeLikeArrayMixin(ExtensionOpsMixin, ExtensionArray):
6668
def asi8(self) -> np.ndarray: ...
6769
@property
6870
def nbytes(self): ...
69-
def __array__(self, dtype=...) -> np.ndarray: ...
71+
def __array__(
72+
self, dtype: NpDtype | None = None, copy: bool | None = None
73+
) -> np_1darray: ...
7074
@property
7175
def size(self) -> int: ...
72-
def __len__(self) -> int: ...
7376
@overload
7477
def __getitem__(self, key: ScalarIndexer) -> DTScalarOrNaT: ...
7578
@overload

pandas-stubs/core/arrays/datetimes.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class DatetimeArray(DatetimeLikeArrayMixin, TimelikeOps, DatelikeOps):
2929
def tzinfo(self) -> _tzinfo | None: ...
3030
@property
3131
def is_normalized(self): ...
32-
def __array__(self, dtype=...) -> np.ndarray: ...
3332
def __iter__(self): ...
3433
def astype(self, dtype, copy: bool = True): ...
3534
def tz_convert(self, tz: TimeZones): ...

pandas-stubs/core/arrays/integer.pyi

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Any
2-
31
from pandas.core.arrays.masked import BaseMaskedArray
42

53
from pandas._libs.missing import NAType
@@ -19,7 +17,6 @@ class IntegerArray(BaseMaskedArray):
1917
@property
2018
def dtype(self) -> _IntegerDtype: ...
2119
def __init__(self, values, mask, copy: bool = ...) -> None: ...
22-
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs: Any): ...
2320
def __setitem__(self, key, value) -> None: ...
2421
def astype(self, dtype, copy: bool = True): ...
2522

pandas-stubs/core/arrays/interval.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ from pandas._libs.interval import (
1818
)
1919
from pandas._typing import (
2020
Axis,
21+
NpDtype,
2122
Scalar,
2223
ScalarIndexer,
2324
SequenceIndexer,
@@ -57,8 +58,9 @@ class IntervalArray(IntervalMixin, ExtensionArray):
5758
copy: bool = False,
5859
dtype=None,
5960
): ...
60-
def __iter__(self): ...
61-
def __len__(self) -> int: ...
61+
def __array__(
62+
self, dtype: NpDtype | None = None, copy: bool | None = None
63+
) -> np_1darray: ...
6264
@overload
6365
def __getitem__(self, key: ScalarIndexer) -> IntervalOrNA: ...
6466
@overload
@@ -100,7 +102,6 @@ class IntervalArray(IntervalMixin, ExtensionArray):
100102
def mid(self) -> Index: ...
101103
@property
102104
def is_non_overlapping_monotonic(self) -> bool: ...
103-
def __array__(self, dtype=...) -> np_1darray: ...
104105
def __arrow_array__(self, type=...): ...
105106
def to_tuples(self, na_tuple: bool = True): ...
106107
def repeat(self, repeats, axis: Axis | None = ...): ...

pandas-stubs/core/arrays/masked.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ from pandas.core.arrays import (
1111
from typing_extensions import Self
1212

1313
from pandas._typing import (
14+
NpDtype,
1415
Scalar,
1516
ScalarIndexer,
1617
SequenceIndexer,
18+
np_1darray,
1719
npt,
1820
)
1921

@@ -23,7 +25,6 @@ class BaseMaskedArray(ExtensionArray, ExtensionOpsMixin):
2325
@overload
2426
def __getitem__(self, item: SequenceIndexer) -> Self: ...
2527
def __iter__(self): ...
26-
def __len__(self) -> int: ...
2728
def __invert__(self): ...
2829
def to_numpy(
2930
self,
@@ -32,7 +33,9 @@ class BaseMaskedArray(ExtensionArray, ExtensionOpsMixin):
3233
na_value: Scalar = ...,
3334
) -> np.ndarray: ...
3435
__array_priority__: int = ...
35-
def __array__(self, dtype=...) -> np.ndarray: ...
36+
def __array__(
37+
self, dtype: NpDtype | None = None, copy: bool | None = None
38+
) -> np_1darray: ...
3639
def __arrow_array__(self, type=...): ...
3740
def isna(self): ...
3841
@property

pandas-stubs/core/arrays/numpy_.pyi

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Any
2-
31
import numpy as np
42
from numpy.lib.mixins import NDArrayOperatorsMixin
53
from pandas.core.arrays.base import (
@@ -15,5 +13,4 @@ class PandasDtype(ExtensionDtype):
1513
@property
1614
def itemsize(self) -> int: ...
1715

18-
class PandasArray(ExtensionArray, ExtensionOpsMixin, NDArrayOperatorsMixin):
19-
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs: Any): ...
16+
class PandasArray(ExtensionArray, ExtensionOpsMixin, NDArrayOperatorsMixin): ...

0 commit comments

Comments
 (0)