Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return Python bool instead of pyarrow boolean scalar for Series reductions #1432

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -419,12 +420,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 @@ -701,9 +702,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
Loading