Skip to content

Commit d1d7675

Browse files
committed
ENH: IMprove boolean array
1 parent c3a11fb commit d1d7675

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

pandas-stubs/core/arrays/boolean.pyi

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
from typing import (
2+
Sequence,
3+
Union,
4+
overload,
5+
)
6+
17
import numpy as np
28
from pandas.core.arrays import ExtensionArray
9+
from typing_extensions import TypeAlias
310

11+
from pandas._libs.missing import NAType
412
from pandas._typing import (
513
Scalar,
14+
npt,
615
type_t,
716
)
817

@@ -22,11 +31,29 @@ class BooleanDtype(ExtensionDtype):
2231
def construct_array_type(cls) -> type_t[BooleanArray]: ...
2332
def __from_arrow__(self, array): ...
2433

34+
_ScalarType: TypeAlias = Union[bool, np.bool_, NAType, None]
35+
_ArrayKey: TypeAlias = Union[Sequence[int], npt.NDArray[np.integer], slice]
36+
2537
class BooleanArray(BaseMaskedArray):
2638
def __init__(
27-
self, values: np.ndarray, mask: np.ndarray, copy: bool = ...
39+
self,
40+
values: npt.NDArray[np.bool_],
41+
mask: npt.NDArray[np.bool_],
42+
copy: bool = ...,
43+
) -> None: ...
44+
# Ignore overrides since more specific than super type
45+
@overload # type: ignore[override]
46+
def __setitem__(self, key: int, value: _ScalarType) -> None: ...
47+
@overload
48+
def __setitem__(
49+
self,
50+
key: _ArrayKey,
51+
value: _ScalarType | Sequence[bool | NAType | None] | npt.NDArray[np.bool_],
2852
) -> None: ...
29-
def __setitem__(self, key: int | np.ndarray | slice, value: object) -> None: ...
53+
@overload # type: ignore[override]
54+
def __getitem__(self, item: int) -> bool | NAType: ...
55+
@overload
56+
def __getitem__(self, item: _ArrayKey) -> BooleanArray: ...
3057
@property
3158
def dtype(self): ...
3259
def astype(

0 commit comments

Comments
 (0)