diff --git a/narwhals/_arrow/expr.py b/narwhals/_arrow/expr.py index d2d51dac7..b8aba0aef 100644 --- a/narwhals/_arrow/expr.py +++ b/narwhals/_arrow/expr.py @@ -395,17 +395,16 @@ def func(df: ArrowDataFrame) -> list[ArrowSeries]: output_names = [input_series.name for input_series in input_series_list] result = [function(series) for series in input_series_list] - if ( - is_numpy_array(result[0]) - or (np := get_numpy()) is not None - and np.isscalar(result[0]) - ): + if is_numpy_array(result[0]): result = [ df.__narwhals_namespace__() ._create_compliant_series(array) .alias(output_name) - if is_numpy_array(array) - else df.__narwhals_namespace__() + for array, output_name in zip(result, output_names) + ] + elif (np := get_numpy()) is not None and np.isscalar(result[0]): + result = [ + df.__narwhals_namespace__() ._create_compliant_series([array]) .alias(output_name) for array, output_name in zip(result, output_names) diff --git a/narwhals/_pandas_like/expr.py b/narwhals/_pandas_like/expr.py index 58ba633dd..6b2487dcb 100644 --- a/narwhals/_pandas_like/expr.py +++ b/narwhals/_pandas_like/expr.py @@ -410,10 +410,8 @@ def func(df: PandasLikeDataFrame) -> list[PandasLikeSeries]: input_series_list = self._call(df) output_names = [input_series.name for input_series in input_series_list] result = [function(series) for series in input_series_list] - if ( - is_numpy_array(result[0]) - or (np := get_numpy()) is not None - and np.isscalar(result[0]) + if is_numpy_array(result[0]) or ( + (np := get_numpy()) is not None and np.isscalar(result[0]) ): result = [ df.__narwhals_namespace__()