Narwhals implementation of lit breaks when it is the left most expr.
Figured this out while doing a fold starting with a lit initial value.
Steps or code to reproduce the bug
import narwhals as nw
import pandas as pd
import polars as pl
import pyarrow as pa
data = {"a": [1, 2, 3]}
df_pd = pd.DataFrame(data)
df_pl = pl.DataFrame(data)
df_pa = pa.table(data)
@nw.narwhalify
def sum_on_the_right(df):
return df.select(nw.col("a") + nw.lit(0))
sum_on_the_right(df_pl), sum_on_the_right(df_pd), sum_on_the_right(df_pa)
# This is all good and well
@nw.narwhalify
def sum_on_the_left(df):
return df.select(nw.lit(0) + nw.col("a"))
sum_on_the_left(df_pl) # polars has no issues
sum_on_the_left(df_pd)
# ValueError: Length mismatch: Expected axis has 3 elements, new values have 1 elements
sum_on_the_left(df_pa)
# ArrowInvalid: Array arguments must all be the same length
Expected results
Being able to broadcast value
Actual results
Broadcast from the left
Please run narwhals.show_version() and enter the output below.
Describe the bug
Narwhals implementation of
lit
breaks when it is the left most expr.Figured this out while doing a fold starting with a lit initial value.
Steps or code to reproduce the bug
Expected results
Being able to broadcast value
Actual results
Broadcast from the left
Please run narwhals.show_version() and enter the output below.
Relevant log output
No response