Skip to content

Commit caaa840

Browse files
authored
fix!: align Series.filter param name with Polars (#2164)
* fix!: align `filter` param name with Polars * fixup
1 parent 0c9c6d8 commit caaa840

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
lines changed

narwhals/_arrow/expr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ def len(self: Self) -> Self:
236236

237237
def filter(self: Self, *predicates: ArrowExpr) -> Self:
238238
plx = self.__narwhals_namespace__()
239-
other = plx.all_horizontal(*predicates)
240-
return reuse_series_implementation(self, "filter", other=other)
239+
predicate = plx.all_horizontal(*predicates)
240+
return reuse_series_implementation(self, "filter", predicate=predicate)
241241

242242
def mean(self: Self) -> Self:
243243
return reuse_series_implementation(self, "mean", returns_scalar=True)

narwhals/_arrow/series.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,13 @@ def _type(self: Self) -> pa.DataType:
271271
def len(self: Self, *, _return_py_scalar: bool = True) -> int:
272272
return maybe_extract_py_scalar(len(self._native_series), _return_py_scalar)
273273

274-
def filter(self: Self, other: ArrowSeries | list[bool | None]) -> Self:
275-
if not (isinstance(other, list) and all(isinstance(x, bool) for x in other)):
276-
_, other_native = extract_native(self, other)
274+
def filter(self: Self, predicate: ArrowSeries | list[bool | None]) -> Self:
275+
if not (
276+
isinstance(predicate, list) and all(isinstance(x, bool) for x in predicate)
277+
):
278+
_, other_native = extract_native(self, predicate)
277279
else:
278-
other_native = other
280+
other_native = predicate
279281
return self._from_native_series(self._native_series.filter(other_native)) # pyright: ignore[reportArgumentType]
280282

281283
def mean(self: Self, *, _return_py_scalar: bool = True) -> float:

narwhals/_pandas_like/expr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ def ewm_mean(
380380

381381
def filter(self: Self, *predicates: PandasLikeExpr) -> Self:
382382
plx = self.__narwhals_namespace__()
383-
other = plx.all_horizontal(*predicates)
384-
return reuse_series_implementation(self, "filter", other=other)
383+
predicate = plx.all_horizontal(*predicates)
384+
return reuse_series_implementation(self, "filter", predicate=predicate)
385385

386386
def drop_nulls(self: Self) -> Self:
387387
return reuse_series_implementation(self, "drop_nulls")

narwhals/_pandas_like/series.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,13 @@ def arg_max(self: Self) -> int:
325325

326326
# Binary comparisons
327327

328-
def filter(self: Self, other: Any) -> PandasLikeSeries:
329-
if not (isinstance(other, list) and all(isinstance(x, bool) for x in other)):
330-
_, other_native = align_and_extract_native(self, other)
328+
def filter(self: Self, predicate: Any) -> PandasLikeSeries:
329+
if not (
330+
isinstance(predicate, list) and all(isinstance(x, bool) for x in predicate)
331+
):
332+
_, other_native = align_and_extract_native(self, predicate)
331333
else:
332-
other_native = other
334+
other_native = predicate
333335
return self._from_native_series(self._native_series.loc[other_native]).alias(
334336
self.name
335337
)

narwhals/series.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,7 @@ def __ror__(self: Self, other: Any) -> Self:
15781578
def __invert__(self: Self) -> Self:
15791579
return self._from_compliant_series(self._compliant_series.__invert__())
15801580

1581-
def filter(self: Self, other: Any) -> Self:
1581+
def filter(self: Self, predicate: Any) -> Self:
15821582
"""Filter elements in the Series based on a condition.
15831583
15841584
Returns:
@@ -1597,7 +1597,7 @@ def filter(self: Self, other: Any) -> Self:
15971597
dtype: int64
15981598
"""
15991599
return self._from_compliant_series(
1600-
self._compliant_series.filter(self._extract_native(other))
1600+
self._compliant_series.filter(self._extract_native(predicate))
16011601
)
16021602

16031603
# --- descriptive ---

0 commit comments

Comments
 (0)