|
10 | 10 | import warnings
|
11 | 11 |
|
12 | 12 | import numpy as np
|
| 13 | +from pandas_mask import PandasMaskArray |
13 | 14 |
|
14 | 15 | from pandas._libs import (
|
15 | 16 | lib,
|
@@ -112,20 +113,23 @@ class BaseMaskedArray(OpsMixin, ExtensionArray):
|
112 | 113 |
|
113 | 114 | # our underlying data and mask are each ndarrays
|
114 | 115 | _data: np.ndarray
|
115 |
| - _mask: npt.NDArray[np.bool_] |
| 116 | + _mask: PandasMaskArray |
116 | 117 |
|
117 | 118 | @classmethod
|
118 | 119 | def _simple_new(cls, values: np.ndarray, mask: npt.NDArray[np.bool_]) -> Self:
|
119 | 120 | result = BaseMaskedArray.__new__(cls)
|
120 | 121 | result._data = values
|
121 |
| - result._mask = mask |
| 122 | + result._mask = PandasMaskArray(mask) |
122 | 123 | return result
|
123 | 124 |
|
124 | 125 | def __init__(
|
125 | 126 | self, values: np.ndarray, mask: npt.NDArray[np.bool_], copy: bool = False
|
126 | 127 | ) -> None:
|
127 | 128 | # values is supposed to already be validated in the subclass
|
128 |
| - if not (isinstance(mask, np.ndarray) and mask.dtype == np.bool_): |
| 129 | + if not ( |
| 130 | + (isinstance(mask, np.ndarray) and mask.dtype == np.bool_) |
| 131 | + or isinstance(mask, PandasMaskArray) |
| 132 | + ): |
129 | 133 | raise TypeError(
|
130 | 134 | "mask should be boolean numpy array. Use "
|
131 | 135 | "the 'pd.array' function instead"
|
@@ -668,7 +672,7 @@ def __arrow_array__(self, type=None):
|
668 | 672 | """
|
669 | 673 | import pyarrow as pa
|
670 | 674 |
|
671 |
| - return pa.array(self._data, mask=self._mask, type=type) |
| 675 | + return pa.array(self._data, mask=np.asarray(self._mask), type=type) |
672 | 676 |
|
673 | 677 | @property
|
674 | 678 | def _hasna(self) -> bool:
|
|
0 commit comments