Skip to content

Commit ec7f401

Browse files
GH1411 Add __and__ for BooleanArray and tests
1 parent bc6e9d4 commit ec7f401

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

pandas-stubs/_typing.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ from typing import (
2121
SupportsIndex,
2222
TypeAlias,
2323
TypedDict,
24-
Union,
2524
overload,
2625
)
2726

@@ -554,7 +553,7 @@ IndexKeyFunc: TypeAlias = Callable[[Index], Index | AnyArrayLike] | None
554553
# types of `func` kwarg for DataFrame.aggregate and Series.aggregate
555554
# More specific than what is in pandas
556555
# following Union is here to make it ty compliant https://github.com/astral-sh/ty/issues/591
557-
AggFuncTypeBase: TypeAlias = Union[Callable, str, np.ufunc] # noqa: UP007
556+
AggFuncTypeBase: TypeAlias = Callable | str | np.ufunc
558557
AggFuncTypeDictSeries: TypeAlias = Mapping[HashableT, AggFuncTypeBase]
559558
AggFuncTypeDictFrame: TypeAlias = Mapping[
560559
HashableT, AggFuncTypeBase | list[AggFuncTypeBase]

pandas-stubs/core/arrays/boolean.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Any
22

33
from pandas.core.arrays.masked import BaseMaskedArray as BaseMaskedArray
4+
from typing_extensions import Self
45

56
from pandas._libs.missing import NAType
67
from pandas._typing import (
@@ -25,3 +26,4 @@ class BooleanArray(BaseMaskedArray):
2526
def __setitem__(self, key, value) -> None: ...
2627
def any(self, *, skipna: bool = ..., **kwargs: Any): ...
2728
def all(self, *, skipna: bool = ..., **kwargs: Any): ...
29+
def __and__(self, other: BooleanArray) -> Self: ...

tests/test_extension.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import numpy as np
44
import pandas as pd
55
from pandas.arrays import IntegerArray
6+
from pandas.core.arrays.boolean import BooleanArray
67
from pandas.core.indexers import check_array_indexer
78
from typing_extensions import assert_type
89

@@ -56,3 +57,11 @@ def test_array_indexer() -> None:
5657
check(assert_type(check_array_indexer(arr, 1), int), int)
5758

5859
check(assert_type(check_array_indexer(arr, slice(0, 1, 1)), slice), slice)
60+
61+
62+
def test_boolean_array() -> None:
63+
"""Test creation of and operations on BooleanArray GH1411."""
64+
arr = pd.array([True], dtype="boolean")
65+
check(assert_type(arr, BooleanArray), BooleanArray)
66+
arr_and = arr.__and__(arr)
67+
check(assert_type(arr_and, BooleanArray), BooleanArray)

0 commit comments

Comments
 (0)