Skip to content

Commit

Permalink
feat: add is_null and __invert__ to pyarrow series (#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianosrp authored Jul 16, 2024
1 parent 616076e commit d01a20d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
6 changes: 6 additions & 0 deletions narwhals/_arrow/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ def __pow__(self, other: ArrowExpr | Any) -> Self:
def __rpow__(self, other: ArrowExpr | Any) -> Self:
return reuse_series_implementation(self, "__rpow__", other)

def __invert__(self) -> Self:
return reuse_series_implementation(self, "__invert__")

def filter(self, *predicates: Any) -> Self:
from narwhals._arrow.namespace import ArrowNamespace

Expand Down Expand Up @@ -183,6 +186,9 @@ def alias(self, name: str) -> Self:
def null_count(self) -> Self:
return reuse_series_implementation(self, "null_count", returns_scalar=True)

def is_null(self) -> Self:
return reuse_series_implementation(self, "is_null")

def head(self, n: int) -> Self:
return reuse_series_implementation(self, "head", n)

Expand Down
8 changes: 8 additions & 0 deletions narwhals/_arrow/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ def __rpow__(self, other: Any) -> Self:
other = validate_column_comparand(other)
return self._from_native_series(pc.power(other, ser))

def __invert__(self) -> Self:
pc = get_pyarrow_compute()
return self._from_native_series(pc.invert(self._native_series))

def filter(self, other: Any) -> Self:
other = validate_column_comparand(other)
return self._from_native_series(self._native_series.filter(other))
Expand Down Expand Up @@ -229,6 +233,10 @@ def all(self) -> bool:
def is_empty(self) -> bool:
return len(self) == 0

def is_null(self) -> Self:
ser = self._native_series
return self._from_native_series(ser.is_null())

def cast(self, dtype: DType) -> Self:
pc = get_pyarrow_compute()
ser = self._native_series
Expand Down
5 changes: 1 addition & 4 deletions tests/frame/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,7 @@ def test_expr_min_max(request: Any, constructor: Any) -> None:
compare_dicts(result_max, expected_max)


def test_expr_na(request: Any, constructor_with_lazy: Any) -> None:
if "pyarrow_table" in str(constructor_with_lazy):
request.applymarker(pytest.mark.xfail)

def test_expr_na(constructor_with_lazy: Any) -> None:
df = nw.from_native(constructor_with_lazy(data_na)).lazy()
result_nna = df.filter((~nw.col("a").is_null()) & (~df.collect()["z"].is_null()))
expected = {"a": [2], "b": [6], "z": [9]}
Expand Down
1 change: 0 additions & 1 deletion utils/check_backend_completeness.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"Series.is_first_distinct",
"Series.is_in",
"Series.is_last_distinct",
"Series.is_null",
"Series.is_sorted",
"Series.is_unique",
"Series.len",
Expand Down

0 comments on commit d01a20d

Please sign in to comment.