Skip to content

Commit 6c5d850

Browse files
authored
Type ExtensionArray.view, ExtensionArray.astype, ExtensionArray.fillna and ExtensionArray.searchsorted (#1435)
* Type ``ExtensionArray.view`` and ``ExtensionArray.searchsorted`` * np.ndarray -> np_1darray * fixup
1 parent 42192e0 commit 6c5d850

File tree

13 files changed

+72
-26
lines changed

13 files changed

+72
-26
lines changed

pandas-stubs/core/arrays/base.pyi

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ from typing_extensions import Self
1414
from pandas._typing import (
1515
AnyArrayLikeInt,
1616
ArrayLike,
17+
AstypeArg,
18+
Dtype,
19+
ListLike,
1720
Scalar,
1821
ScalarIndexer,
1922
SequenceIndexer,
@@ -50,16 +53,36 @@ class ExtensionArray:
5053
def ndim(self) -> int: ...
5154
@property
5255
def nbytes(self) -> int: ...
53-
def astype(self, dtype, copy: bool = True): ...
56+
@overload
57+
def astype(self, dtype: np.dtype, copy: bool = True) -> np_1darray: ...
58+
@overload
59+
def astype(self, dtype: ExtensionDtype, copy: bool = True) -> ExtensionArray: ...
60+
@overload
61+
def astype(self, dtype: AstypeArg, copy: bool = True) -> ArrayLike: ...
5462
def isna(self) -> ArrayLike: ...
5563
def argsort(
5664
self, *, ascending: bool = ..., kind: str = ..., **kwargs: Any
5765
) -> np_1darray: ...
58-
def fillna(self, value=..., method=None, limit=None): ...
66+
def fillna(
67+
self, value: object | ArrayLike, limit: int | None = None, copy: bool = True
68+
) -> Self: ...
5969
def dropna(self) -> Self: ...
6070
def shift(self, periods: int = 1, fill_value: object = ...) -> Self: ...
6171
def unique(self) -> Self: ...
62-
def searchsorted(self, value, side: str = ..., sorter=...): ...
72+
@overload
73+
def searchsorted(
74+
self,
75+
value: ListLike,
76+
side: Literal["left", "right"] = ...,
77+
sorter: ListLike | None = ...,
78+
) -> np_1darray[np.intp]: ...
79+
@overload
80+
def searchsorted(
81+
self,
82+
value: Scalar,
83+
side: Literal["left", "right"] = ...,
84+
sorter: ListLike | None = ...,
85+
) -> np.intp: ...
6386
def factorize(self, use_na_sentinel: bool = True) -> tuple[np_1darray, Self]: ...
6487
def repeat(
6588
self, repeats: int | AnyArrayLikeInt | Sequence[int], axis: None = None
@@ -72,11 +95,14 @@ class ExtensionArray:
7295
fill_value: Any = None,
7396
) -> Self: ...
7497
def copy(self) -> Self: ...
75-
def view(self, dtype=...) -> Self | np_1darray: ...
98+
@overload
99+
def view(self, dtype: None = None) -> Self: ...
100+
@overload
101+
def view(self, dtype: Dtype) -> ArrayLike: ...
76102
def ravel(self, order: Literal["C", "F", "A", "K"] | None = "C") -> Self: ...
77-
def tolist(self) -> list: ...
103+
def tolist(self) -> list[Any]: ...
78104
def _reduce(
79-
self, name: str, *, skipna: bool = ..., keepdims: bool = ..., **kwargs: Any
105+
self, name: str, *, skipna: bool = True, keepdims: bool = False, **kwargs: Any
80106
) -> object: ...
81107
def _accumulate(
82108
self,

pandas-stubs/core/arrays/boolean.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,5 @@ class BooleanArray(BaseMaskedArray):
2121
@property
2222
def dtype(self): ...
2323
def __setitem__(self, key, value) -> None: ...
24-
def astype(self, dtype, copy: bool = True): ...
2524
def any(self, *, skipna: bool = ..., **kwargs: Any): ...
2625
def all(self, *, skipna: bool = ..., **kwargs: Any): ...

pandas-stubs/core/arrays/categorical.pyi

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ from pandas.core.indexes.base import Index
1616
from typing_extensions import Self
1717

1818
from pandas._typing import (
19-
ArrayLike,
20-
Dtype,
2119
ListLike,
2220
NpDtype,
2321
Ordered,
@@ -49,7 +47,6 @@ class Categorical(ExtensionArray):
4947
def ordered(self) -> Ordered: ...
5048
@property
5149
def dtype(self) -> CategoricalDtype: ...
52-
def astype(self, dtype: Dtype, copy: bool = True) -> ArrayLike: ...
5350
def size(self) -> int: ...
5451
def tolist(self) -> list[Scalar]: ...
5552
to_list = ...
@@ -110,7 +107,6 @@ class Categorical(ExtensionArray):
110107
self, *, inplace: bool = ..., ascending: bool = ..., na_position: str = ...
111108
): ...
112109
def view(self, dtype=...): ...
113-
def fillna(self, value=..., method=None, limit=None): ...
114110
def take(
115111
self, indexer: TakeIndexer, *, allow_fill: bool = ..., fill_value=...
116112
) -> Categorical: ...

pandas-stubs/core/arrays/datetimelike.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ class DatetimeLikeArrayMixin(ExtensionOpsMixin, ExtensionArray):
8383
def __setitem__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
8484
self, key: int | Sequence[int] | Sequence[bool] | slice, value
8585
) -> None: ...
86-
def astype(self, dtype, copy: bool = True): ...
8786
def view(self, dtype=...): ...
8887
def unique(self): ...
8988
def copy(self): ...
@@ -92,7 +91,6 @@ class DatetimeLikeArrayMixin(ExtensionOpsMixin, ExtensionArray):
9291
def value_counts(self, dropna: bool = True): ...
9392
def map(self, mapper): ...
9493
def isna(self): ...
95-
def fillna(self, value=..., method=None, limit=None): ...
9694
@property
9795
def freq(self): ...
9896
@freq.setter

pandas-stubs/core/arrays/datetimes.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class DatetimeArray(DatetimeLikeArrayMixin, TimelikeOps, DatelikeOps):
3030
@property
3131
def is_normalized(self): ...
3232
def __iter__(self): ...
33-
def astype(self, dtype, copy: bool = True): ...
3433
def tz_convert(self, tz: TimeZones): ...
3534
def tz_localize(
3635
self,

pandas-stubs/core/arrays/integer.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class IntegerArray(BaseMaskedArray):
1818
def dtype(self) -> _IntegerDtype: ...
1919
def __init__(self, values, mask, copy: bool = ...) -> None: ...
2020
def __setitem__(self, key, value) -> None: ...
21-
def astype(self, dtype, copy: bool = True): ...
2221

2322
class Int8Dtype(_IntegerDtype): ...
2423
class Int16Dtype(_IntegerDtype): ...

pandas-stubs/core/arrays/interval.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,8 @@ class IntervalArray(IntervalMixin, ExtensionArray):
6868
def __setitem__(self, key, value) -> None: ...
6969
def __eq__(self, other): ...
7070
def __ne__(self, other): ...
71-
def fillna(self, value=..., method=None, limit=None): ...
7271
@property
7372
def dtype(self): ...
74-
def astype(self, dtype, copy: bool = True): ...
7573
def copy(self): ...
7674
def isna(self): ...
7775
@property

pandas-stubs/core/arrays/period.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,3 @@ class PeriodArray(DatetimeLikeArrayMixin, DatelikeOps):
4747
self, freq: PeriodFrequency | None = None, how: str = ...
4848
) -> Timestamp: ...
4949
def asfreq(self, freq: str | None = ..., how: str = "E") -> Period: ...
50-
def astype(self, dtype, copy: bool = True): ...

pandas-stubs/core/arrays/sparse/array.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class SparseArray(ExtensionArray, ExtensionOpsMixin):
5757
@property
5858
def npoints(self) -> int: ...
5959
def isna(self): ...
60-
def fillna(self, value=..., method=..., limit=...): ...
6160
def shift(self, periods: int = 1, fill_value=...): ...
6261
def unique(self): ...
6362
def value_counts(self, dropna: bool = True): ...
@@ -69,7 +68,6 @@ class SparseArray(ExtensionArray, ExtensionOpsMixin):
6968
key: SequenceIndexer | tuple[int | ellipsis, ...],
7069
) -> Self: ...
7170
def copy(self): ...
72-
def astype(self, dtype=..., copy: bool = True): ...
7371
def map(self, mapper): ...
7472
def to_dense(self): ...
7573
def nonzero(self): ...

pandas-stubs/core/arrays/string_.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,4 @@ class StringArray(PandasArray):
1515
def __init__(self, values, copy: bool = ...) -> None: ...
1616
def __arrow_array__(self, type=...): ...
1717
def __setitem__(self, key, value) -> None: ...
18-
def fillna(self, value=..., method=None, limit=None): ...
19-
def astype(self, dtype, copy: bool = True): ...
2018
def value_counts(self, dropna: bool = True): ...

0 commit comments

Comments
 (0)