1818from narwhals .dependencies import is_numpy_array
1919from narwhals .exceptions import LengthChangingExprError
2020from narwhals .exceptions import ShapeError
21- from narwhals .utils import Implementation
2221from narwhals .utils import is_compliant_expr
2322from narwhals .utils import is_eager_namespace
2423
2524if TYPE_CHECKING :
2625 from typing_extensions import Never
2726 from typing_extensions import TypeIs
2827
29- from narwhals ._arrow .expr import ArrowExpr
3028 from narwhals ._compliant import CompliantExpr
3129 from narwhals ._compliant import CompliantFrameT
3230 from narwhals ._compliant import CompliantNamespace
4139 from narwhals .typing import _1DArray
4240
4341 PandasLikeExprT = TypeVar ("PandasLikeExprT" , bound = PandasLikeExpr )
44- ArrowExprT = TypeVar ("ArrowExprT" , bound = ArrowExpr )
4542
4643 T = TypeVar ("T" )
4744
@@ -105,34 +102,14 @@ def maybe_evaluate_expr(
105102 return expr
106103
107104
108- @overload
109105def reuse_series_implementation (
110106 expr : PandasLikeExprT ,
111107 attr : str ,
112108 * ,
113109 returns_scalar : bool = False ,
114- ** kwargs : Any ,
115- ) -> PandasLikeExprT : ...
116-
117-
118- @overload
119- def reuse_series_implementation (
120- expr : ArrowExprT ,
121- attr : str ,
122- * ,
123- returns_scalar : bool = False ,
124- ** kwargs : Any ,
125- ) -> ArrowExprT : ...
126-
127-
128- def reuse_series_implementation (
129- expr : ArrowExprT | PandasLikeExprT ,
130- attr : str ,
131- * ,
132- returns_scalar : bool = False ,
133110 call_kwargs : dict [str , Any ] | None = None ,
134111 ** expressifiable_args : Any ,
135- ) -> ArrowExprT | PandasLikeExprT :
112+ ) -> PandasLikeExprT :
136113 """Reuse Series implementation for expression.
137114
138115 If Series.foo is already defined, and we'd like Expr.foo to be the same, we can
@@ -159,18 +136,10 @@ def func(df: CompliantDataFrame[Any]) -> Sequence[CompliantSeries]:
159136 },
160137 }
161138
162- # For PyArrow.Series, we return Python Scalars (like Polars does) instead of PyArrow Scalars.
163- # However, when working with expressions, we keep everything PyArrow-native.
164- extra_kwargs = (
165- {"_return_py_scalar" : False }
166- if returns_scalar and expr ._implementation is Implementation .PYARROW
167- else {}
168- )
169-
170139 out : list [CompliantSeries ] = [
171- plx ._create_series_from_scalar ( # type: ignore # noqa: PGH003
172- getattr (series , attr )(** extra_kwargs , ** _kwargs ),
173- reference_series = series , # type: ignore[arg-type]
140+ plx ._create_series_from_scalar (
141+ getattr (series , attr )(** _kwargs ),
142+ reference_series = series ,
174143 )
175144 if returns_scalar
176145 else getattr (series , attr )(** _kwargs )
@@ -186,30 +155,22 @@ def func(df: CompliantDataFrame[Any]) -> Sequence[CompliantSeries]:
186155 raise AssertionError (msg )
187156 return out
188157
189- return plx ._create_expr_from_callable ( # type: ignore[return-value, union-attr ]
158+ return plx ._create_expr_from_callable ( # type: ignore[return-value]
190159 func , # type: ignore[arg-type]
191160 depth = expr ._depth + 1 ,
192161 function_name = f"{ expr ._function_name } ->{ attr } " ,
193- evaluate_output_names = expr ._evaluate_output_names , # type: ignore[arg-type]
162+ evaluate_output_names = expr ._evaluate_output_names ,
194163 alias_output_names = expr ._alias_output_names ,
195164 call_kwargs = call_kwargs ,
196165 )
197166
198167
199- @overload
200- def reuse_series_namespace_implementation (
201- expr : ArrowExprT , series_namespace : str , attr : str , ** kwargs : Any
202- ) -> ArrowExprT : ...
203- @overload
204168def reuse_series_namespace_implementation (
205- expr : PandasLikeExprT , series_namespace : str , attr : str , ** kwargs : Any
206- ) -> PandasLikeExprT : ...
207- def reuse_series_namespace_implementation (
208- expr : ArrowExprT | PandasLikeExprT ,
169+ expr : PandasLikeExprT ,
209170 series_namespace : str ,
210171 attr : str ,
211172 ** kwargs : Any ,
212- ) -> ArrowExprT | PandasLikeExprT :
173+ ) -> PandasLikeExprT :
213174 """Reuse Series implementation for expression.
214175
215176 Just like `reuse_series_implementation`, but for e.g. `Expr.dt.foo` instead
@@ -222,14 +183,14 @@ def reuse_series_namespace_implementation(
222183 kwargs: keyword arguments to pass to function.
223184 """
224185 plx = expr .__narwhals_namespace__ ()
225- return plx ._create_expr_from_callable ( # type: ignore[return-value, union-attr ]
186+ return plx ._create_expr_from_callable ( # type: ignore[return-value]
226187 lambda df : [
227188 getattr (getattr (series , series_namespace ), attr )(** kwargs )
228- for series in expr (df ) # type: ignore[arg-type]
189+ for series in expr (df )
229190 ],
230191 depth = expr ._depth + 1 ,
231192 function_name = f"{ expr ._function_name } ->{ series_namespace } .{ attr } " ,
232- evaluate_output_names = expr ._evaluate_output_names , # type: ignore[arg-type]
193+ evaluate_output_names = expr ._evaluate_output_names ,
233194 alias_output_names = expr ._alias_output_names ,
234195 )
235196
0 commit comments