From 118c7152924c50041d92fb4bb2eaf06e129c60b5 Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Mon, 11 Nov 2024 17:55:19 +0000 Subject: [PATCH] split out --- narwhals/_arrow/expr.py | 13 ++++++------- narwhals/_pandas_like/expr.py | 6 ++---- 2 files changed, 8 insertions(+), 11 deletions(-) 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__()