3434from narwhals .utils import flatten
3535from narwhals .utils import generate_repr
3636from narwhals .utils import is_compliant_lazyframe
37+ from narwhals .utils import is_list_of
3738from narwhals .utils import is_sequence_but_not_str
3839from narwhals .utils import issue_deprecation_warning
3940from narwhals .utils import parse_version
@@ -192,11 +193,9 @@ def filter(
192193 * predicates : IntoExpr | Iterable [IntoExpr ] | list [bool ],
193194 ** constraints : Any ,
194195 ) -> Self :
195- if not (
196- len (predicates ) == 1
197- and isinstance (predicates [0 ], list )
198- and all (isinstance (x , bool ) for x in predicates [0 ])
199- ):
196+ if len (predicates ) == 1 and is_list_of (predicates [0 ], bool ):
197+ predicate = predicates [0 ]
198+ else :
200199 from narwhals .functions import col
201200
202201 flat_predicates = flatten (predicates )
@@ -210,8 +209,6 @@ def filter(
210209 predicate = plx .all_horizontal (
211210 * chain (compliant_predicates , compliant_constraints )
212211 )
213- else :
214- predicate = predicates [0 ]
215212 return self ._with_compliant (self ._compliant_frame .filter (predicate ))
216213
217214 def sort (
@@ -2786,10 +2783,7 @@ def filter(
27862783 <BLANKLINE>
27872784 """
27882785 if (
2789- len (predicates ) == 1
2790- and isinstance (predicates [0 ], list )
2791- and all (isinstance (x , bool ) for x in predicates [0 ])
2792- and not constraints
2786+ len (predicates ) == 1 and is_list_of (predicates [0 ], bool ) and not constraints
27932787 ): # pragma: no cover
27942788 msg = "`LazyFrame.filter` is not supported with Python boolean masks - use expressions instead."
27952789 raise TypeError (msg )
0 commit comments