Skip to content

Commit

Permalink
Use pandas_bitmask library
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAyd committed Nov 27, 2024
1 parent fae3e80 commit 5b51bde
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ dependencies:
- pygments # Code highlighting

- pip:
- git+https://github.com/WillAyd/pandas-bitmask.git
- adbc-driver-postgresql>=0.10.0
- adbc-driver-sqlite>=0.8.0
- typing_extensions; python_version<"3.11"
Expand Down
12 changes: 8 additions & 4 deletions pandas/core/arrays/masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import warnings

import numpy as np
from pandas_mask import PandasMaskArray

from pandas._libs import (
lib,
Expand Down Expand Up @@ -112,20 +113,23 @@ class BaseMaskedArray(OpsMixin, ExtensionArray):

# our underlying data and mask are each ndarrays
_data: np.ndarray
_mask: npt.NDArray[np.bool_]
_mask: PandasMaskArray

@classmethod
def _simple_new(cls, values: np.ndarray, mask: npt.NDArray[np.bool_]) -> Self:
result = BaseMaskedArray.__new__(cls)
result._data = values
result._mask = mask
result._mask = PandasMaskArray(mask)
return result

def __init__(
self, values: np.ndarray, mask: npt.NDArray[np.bool_], copy: bool = False
) -> None:
# values is supposed to already be validated in the subclass
if not (isinstance(mask, np.ndarray) and mask.dtype == np.bool_):
if not (
(isinstance(mask, np.ndarray) and mask.dtype == np.bool_)
or isinstance(mask, PandasMaskArray)
):
raise TypeError(
"mask should be boolean numpy array. Use "
"the 'pd.array' function instead"
Expand Down Expand Up @@ -678,7 +682,7 @@ def __arrow_array__(self, type=None):
"""
import pyarrow as pa

return pa.array(self._data, mask=self._mask, type=type)
return pa.array(self._data, mask=np.asarray(self._mask), type=type)

@property
def _hasna(self) -> bool:
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ feedparser
pyyaml
requests
pygments
git+https://github.com/WillAyd/pandas-bitmask.git
adbc-driver-postgresql>=0.10.0
adbc-driver-sqlite>=0.8.0
typing_extensions; python_version<"3.11"
Expand Down

0 comments on commit 5b51bde

Please sign in to comment.