Skip to content

Commit

Permalink
is_bool_sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemanley committed Dec 24, 2024
1 parent 77cb956 commit c6643df
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions py-polars/polars/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from polars._utils.various import (
BUILDING_SPHINX_DOCS,
_is_generator,
is_bool_sequence,
no_default,
parse_version,
scale_bytes,
Expand Down Expand Up @@ -3034,7 +3035,7 @@ def extend(self, other: Series) -> Self:
raise
return self

def filter(self, predicate: Series | list[bool] | np.ndarray[Any, Any]) -> Self:
def filter(self, predicate: Series | Sequence[bool]) -> Self:
"""
Filter elements by a boolean mask.
Expand All @@ -3060,7 +3061,9 @@ def filter(self, predicate: Series | list[bool] | np.ndarray[Any, Any]) -> Self:
3
]
"""
if isinstance(predicate, (list, np.ndarray)):
if is_bool_sequence(predicate, include_series=True):
predicate = Series("", predicate, dtype=Boolean)
elif isinstance(predicate, Sequence):
predicate = Series("", predicate)
return self._from_pyseries(self._s.filter(predicate._s))

Expand Down

0 comments on commit c6643df

Please sign in to comment.