Skip to content

[Bug]: group_by context ignores expr arguments #1606

@FBruzzesi

Description

@FBruzzesi

Describe the bug

For expressions that accept arguments, these are not passed along in group_by context (e.g. ddof in std).

Steps or code to reproduce the bug

import narwhals as nw
import pandas as pd
import polars as pl

data = {"a": [1, 1, 1, 1, 1, 2, 2, 2, 2, 2], "b": list(range(10))}

nw.from_native(pl.DataFrame(data)).group_by("a").agg(nw.col("b").std(ddof=2)).to_native()
shape: (2, 2)
┌─────┬──────────┐
│ ab        │
│ ------      │
│ i64f64      │
╞═════╪══════════╡
│ 21.825742 │
│ 11.825742 │
└─────┴──────────┘

nw.from_native(pd.DataFrame(data)).group_by("a").agg(nw.col("b").std(ddof=2)).to_native()
   a         b
0  1  1.581139
1  2  1.581139

# which is the same as ddof=1

nw.from_native(pd.DataFrame(data)).group_by("a").agg(nw.col("b").std(ddof=1)).to_native()
   a         b
0  1  1.581139
1  2  1.581139

Expected results

Arguments to be passed along or raise

Actual results

Arguments get ignored

Please run narwhals.show_version() and enter the output below.

System:
    python: 3.12.2 (main, Feb 25 2024, 16:35:05) [GCC 11.4.0]

Python dependencies:
     narwhals: 1.18.4
       pandas: 2.2.3
       polars: 1.17.1
         cudf: 
        modin: 0.32.0
      pyarrow: 18.1.0
        numpy: 2.1.3

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug: incorrect resultSomething isn't workinghigh priorityYour PR will be reviewed very quickly if you address this

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions