2727 import pyarrow as pa
2828 from typing_extensions import Self
2929 from typing_extensions import TypeAlias
30- from typing_extensions import TypeIs
3130
32- from narwhals ._compliant .expr import EagerExpr
3331 from narwhals .dtypes import DType
3432 from narwhals .typing import SizeUnit
3533 from narwhals .typing import _2DArray
@@ -178,17 +176,16 @@ class EagerDataFrame(
178176 CompliantDataFrame [EagerSeriesT , EagerExprT_contra ],
179177 Protocol [EagerSeriesT , EagerExprT_contra ],
180178):
181- def _maybe_evaluate_expr (self , expr : EagerExprT_contra | T , / ) -> EagerSeriesT | T :
182- if is_eager_expr (expr ):
183- result : Sequence [EagerSeriesT ] = expr (self )
184- if len (result ) > 1 :
185- msg = (
186- "Multi-output expressions (e.g. `nw.all()` or `nw.col('a', 'b')`) "
187- "are not supported in this context"
188- )
189- raise ValueError (msg )
190- return result [0 ]
191- return expr
179+ def _evaluate_expr (self , expr : EagerExprT_contra , / ) -> EagerSeriesT :
180+ """Evaluate `expr` and ensure it has a **single** output."""
181+ result : Sequence [EagerSeriesT ] = expr (self )
182+ if len (result ) > 1 :
183+ msg = (
184+ "Multi-output expressions (e.g. `nw.all()` or `nw.col('a', 'b')`) "
185+ "are not supported in this context"
186+ )
187+ raise ValueError (msg )
188+ return result [0 ]
192189
193190 def _evaluate_into_exprs (self , * exprs : EagerExprT_contra ) -> Sequence [EagerSeriesT ]:
194191 return list (chain .from_iterable (self ._evaluate_into_expr (expr ) for expr in exprs ))
@@ -209,11 +206,3 @@ def _evaluate_into_expr(self, expr: EagerExprT_contra, /) -> Sequence[EagerSerie
209206 msg = f"Safety assertion failed, expected { aliases } , got { result } "
210207 raise AssertionError (msg )
211208 return result
212-
213-
214- # NOTE: `mypy` is requiring the gymnastics here and is very fragile
215- # DON'T CHANGE THIS or `EagerDataFrame._maybe_evaluate_expr`
216- def is_eager_expr (
217- obj : EagerExpr [Any , EagerSeriesT ] | Any ,
218- ) -> TypeIs [EagerExpr [Any , EagerSeriesT ]]:
219- return hasattr (obj , "__narwhals_expr__" )
0 commit comments