Skip to content

Commit

Permalink
use default context for col upstream col expression type (#4219)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Aug 2, 2022
1 parent b2ff9fa commit af35ce0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions polars/polars-lazy/src/logical_plan/aexpr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ impl AExpr {
} => {
let fields = input
.iter()
.map(|node| arena.get(*node).to_field(schema, ctxt, arena))
// default context because `col()` would return a list in aggregation context
.map(|node| arena.get(*node).to_field(schema, Context::Default, arena))
.collect::<Result<Vec<_>>>()?;
Ok(output_type.get_field(schema, ctxt, &fields))
}
Expand All @@ -343,7 +344,8 @@ impl AExpr {
} => {
let fields = input
.iter()
.map(|node| arena.get(*node).to_field(schema, ctxt, arena))
// default context because `col()` would return a list in aggregation context
.map(|node| arena.get(*node).to_field(schema, Context::Default, arena))
.collect::<Result<Vec<_>>>()?;
function.get_field(schema, ctxt, &fields)
}
Expand Down
7 changes: 7 additions & 0 deletions py-polars/tests/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,3 +607,10 @@ def test_nested_struct_sliced_append() -> None:
{"_experience": {"aaid": {"id": "B", "namespace": {"code": "bravo"}}}},
{"_experience": {"aaid": {"id": "D", "namespace": {"code": "delta"}}}},
]


def test_struct_groupby_field_agg_4216() -> None:
df = pl.DataFrame([{"a": {"b": 1}, "c": 0}])
assert df.groupby("c").agg(pl.col("a").struct.field("b").count()).to_dict(
False
) == {"c": [0], "b": [1]}

0 comments on commit af35ce0

Please sign in to comment.