|
3 | 3 | import numpy as np |
4 | 4 | import pandas as pd |
5 | 5 | from pandas.arrays import IntegerArray |
| 6 | +from pandas.core.arrays.boolean import BooleanArray |
6 | 7 | from pandas.core.indexers import check_array_indexer |
7 | 8 | from typing_extensions import assert_type |
8 | 9 |
|
@@ -56,3 +57,24 @@ def test_array_indexer() -> None: |
56 | 57 | check(assert_type(check_array_indexer(arr, 1), int), int) |
57 | 58 |
|
58 | 59 | 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 | + arr_bool = pd.array([True, False]) |
| 66 | + arr_int = pd.array([3, 5]) |
| 67 | + check(assert_type(arr, BooleanArray), BooleanArray) |
| 68 | + arr_and = arr & arr |
| 69 | + check(assert_type(arr_and, BooleanArray), BooleanArray) |
| 70 | + |
| 71 | + check(assert_type(arr_bool & True, BooleanArray), BooleanArray) |
| 72 | + check(assert_type(arr_bool & np.bool(True), BooleanArray), BooleanArray) |
| 73 | + check(assert_type(arr_bool & pd.NA, BooleanArray), BooleanArray) |
| 74 | + check(assert_type(arr_bool & [True, False], BooleanArray), BooleanArray) |
| 75 | + check(assert_type(arr_bool & [np.bool(True), False], BooleanArray), BooleanArray) |
| 76 | + # TODO: pandas-dev/pandas#63095 |
| 77 | + # check(assert_type(b & [pd.NA, False]) |
| 78 | + check(assert_type(arr_bool & np.array([True, False]), BooleanArray), BooleanArray) |
| 79 | + check(assert_type(arr_bool & arr_int, BooleanArray), BooleanArray) |
| 80 | + check(assert_type(arr_bool & arr_bool, BooleanArray), BooleanArray) |
0 commit comments