Skip to content

Commit

Permalink
fix: return Python bool instead of pyarrow boolean scalar for Series …
Browse files Browse the repository at this point in the history
…reductions (#1432)
  • Loading branch information
MarcoGorelli authored Nov 23, 2024
1 parent 8973d50 commit fd6f8fd
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions narwhals/_arrow/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from narwhals._arrow.utils import native_to_narwhals_dtype
from narwhals._arrow.utils import parse_datetime_format
from narwhals._arrow.utils import validate_column_comparand
from narwhals.translate import to_py_scalar
from narwhals.utils import Implementation
from narwhals.utils import generate_temporary_column_name

Expand Down Expand Up @@ -437,12 +438,12 @@ def diff(self) -> Self:
def any(self) -> bool:
import pyarrow.compute as pc # ignore-banned-import()

return pc.any(self._native_series) # type: ignore[no-any-return]
return to_py_scalar(pc.any(self._native_series)) # type: ignore[no-any-return]

def all(self) -> bool:
import pyarrow.compute as pc # ignore-banned-import()

return pc.all(self._native_series) # type: ignore[no-any-return]
return to_py_scalar(pc.all(self._native_series)) # type: ignore[no-any-return]

def is_between(
self, lower_bound: Any, upper_bound: Any, closed: str = "both"
Expand Down Expand Up @@ -719,9 +720,10 @@ def is_sorted(self: Self, *, descending: bool = False) -> bool:

ser = self._native_series
if descending:
return pc.all(pc.greater_equal(ser[:-1], ser[1:])) # type: ignore[no-any-return]
result = pc.all(pc.greater_equal(ser[:-1], ser[1:]))
else:
return pc.all(pc.less_equal(ser[:-1], ser[1:])) # type: ignore[no-any-return]
result = pc.all(pc.less_equal(ser[:-1], ser[1:]))
return to_py_scalar(result) # type: ignore[no-any-return]

def unique(self: Self, *, maintain_order: bool = False) -> ArrowSeries:
# The param `maintain_order` is only here for compatibility with the Polars API
Expand Down

0 comments on commit fd6f8fd

Please sign in to comment.