Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Implement isnan ufunc (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhochy authored Sep 16, 2020
1 parent 4f4e210 commit b717a3b
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions fletcher/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from pandas.core.dtypes.dtypes import ExtensionDtype, register_extension_dtype

from fletcher._algorithms import (
extract_isnull_bytemap,
kurt_op,
max_op,
median_op,
Expand Down Expand Up @@ -432,14 +431,6 @@ def __len__(self) -> int:
"""
return self.shape[0]

def isna(self) -> np.ndarray:
"""
Boolean NumPy array indicating if each value is missing.
This should return a 1-D array the same length as 'self'.
"""
return extract_isnull_bytemap(self.data)

@property
def base(self) -> Union[pa.Array, pa.ChunkedArray]:
"""Return base object of the underlying data."""
Expand Down Expand Up @@ -531,6 +522,13 @@ def __array_ufunc__(self, ufunc, method: str, *inputs, **kwargs):
raise NotImplementedError(
f"Only method == '__call__' is supported in ufuncs, not '{method}'"
)
if len(inputs) == 1:
if getattr(ufunc, "__name__") == "isnan":
return self.isna()
else:
raise NotImplementedError(
f"ufunc with single input not supported: {ufunc}"
)
if len(inputs) != 2:
raise NotImplementedError("Only ufuncs with a second input are supported")
if len(kwargs) > 0:
Expand Down Expand Up @@ -843,6 +841,14 @@ def value_counts(self, dropna: bool = True) -> "pd.Series":

return pd.Series(counts, index=index)

def isna(self) -> np.ndarray:
"""
Boolean NumPy array indicating if each value is missing.
This should return a 1-D array the same length as 'self'.
"""
return np.array(self.data.is_null())


class FletcherContinuousArray(FletcherBaseArray):
"""Pandas ExtensionArray implementation backed by Apache Arrow's pyarrow.Array."""
Expand Down

0 comments on commit b717a3b

Please sign in to comment.