Skip to content

Commit 9f561c1

Browse files
committed
Use pandas_bitmask library
1 parent 139def2 commit 9f561c1

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

environment.yml

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ dependencies:
116116
- pygments # Code highlighting
117117

118118
- pip:
119+
- git+https://github.com/WillAyd/pandas-bitmask.git
119120
- adbc-driver-postgresql>=0.10.0
120121
- adbc-driver-sqlite>=0.8.0
121122
- typing_extensions; python_version<"3.11"

pandas/core/arrays/masked.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import warnings
1111

1212
import numpy as np
13+
from pandas_mask import PandasMaskArray
1314

1415
from pandas._libs import (
1516
lib,
@@ -112,20 +113,23 @@ class BaseMaskedArray(OpsMixin, ExtensionArray):
112113

113114
# our underlying data and mask are each ndarrays
114115
_data: np.ndarray
115-
_mask: npt.NDArray[np.bool_]
116+
_mask: PandasMaskArray
116117

117118
@classmethod
118119
def _simple_new(cls, values: np.ndarray, mask: npt.NDArray[np.bool_]) -> Self:
119120
result = BaseMaskedArray.__new__(cls)
120121
result._data = values
121-
result._mask = mask
122+
result._mask = PandasMaskArray(mask)
122123
return result
123124

124125
def __init__(
125126
self, values: np.ndarray, mask: npt.NDArray[np.bool_], copy: bool = False
126127
) -> None:
127128
# 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+
):
129133
raise TypeError(
130134
"mask should be boolean numpy array. Use "
131135
"the 'pd.array' function instead"
@@ -668,7 +672,7 @@ def __arrow_array__(self, type=None):
668672
"""
669673
import pyarrow as pa
670674

671-
return pa.array(self._data, mask=self._mask, type=type)
675+
return pa.array(self._data, mask=np.asarray(self._mask), type=type)
672676

673677
@property
674678
def _hasna(self) -> bool:

requirements-dev.txt

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ feedparser
8484
pyyaml
8585
requests
8686
pygments
87+
git+https://github.com/WillAyd/pandas-bitmask.git
8788
adbc-driver-postgresql>=0.10.0
8889
adbc-driver-sqlite>=0.8.0
8990
typing_extensions; python_version<"3.11"

0 commit comments

Comments
 (0)