Skip to content

Commit

Permalink
try filter fastpath
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Mar 18, 2024
1 parent 60e7898 commit 2de91c3
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions narwhals/pandas_like/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,23 @@ def select(

def filter(
self,
*predicates: IntoPandasExpr | Iterable[IntoPandasExpr],
*predicates: Iterable[IntoPandasExpr],
) -> Self:
from narwhals.pandas_like.namespace import PandasNamespace

plx = PandasNamespace(self._implementation)
expr = plx.all_horizontal(*predicates)
# Safety: all_horizontal's expression only returns a single column.
mask = expr._call(self)[0]
_mask = validate_dataframe_comparand(mask)
return self._from_dataframe(self._dataframe[_mask])
masks = evaluate_into_exprs(self, *predicates)
if len(masks) == 1:
return self._from_dataframe(
self._dataframe[validate_dataframe_comparand(masks[0])]
)

return self._from_dataframe(
self._dataframe[
validate_dataframe_comparand(
horizontal_concat(masks, implementation=self._implementation).all(
axis=1
)
)
]
)

def with_columns(
self,
Expand Down

0 comments on commit 2de91c3

Please sign in to comment.