Skip to content

enh: allow for scalars in sum_horizontal #1868

@MarcoGorelli

Description

@MarcoGorelli

e.g.

import duckdb
import narwhals as nw
rel = duckdb.sql('select * from values (1, 4), (1, 2), (2, 3), (2, 4) df(a, b)')
df = nw.from_native(rel)
 df.select(nw.sum_horizontal(1, 'a', 'b'))

throws

InvalidIntoExprError: Expected an object which can be converted into an expression, got <class 'int'>

Hint:
- if you were trying to select a column which does not have a string
  column name, then you should explicitly use `nw.col`.
  For example, `df.select(nw.col(0))` if you have a column named `0`.
- if you were trying to create a new literal column, then you
  should explicitly use `nw.lit`.
  For example, `df.select(nw.lit(0))` if you want to create a new
  column with literal value `0`.

I think we should have a way of allowing for anything which can't be parsed as an expression to be parsed as nw.lit in these cases

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions