Skip to content

Commit

Permalink
fix: Allow .struct.with_fields inside list.eval (#19617)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdlineluser authored Nov 4, 2024
1 parent 865a02d commit 7be7f06
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/polars-plan/src/dsl/struct_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl StructNameSpace {
function: FunctionExpr::StructExpr(StructFunction::WithFields),
options: FunctionOptions {
collect_groups: ApplyOptions::ElementWise,
flags: FunctionFlags::default() & !FunctionFlags::ALLOW_GROUP_AWARE
flags: FunctionFlags::default()
| FunctionFlags::PASS_NAME_TO_APPLY
| FunctionFlags::INPUT_WILDCARD_EXPANSION,
..Default::default()
Expand Down
28 changes: 28 additions & 0 deletions py-polars/tests/unit/datatypes/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -1186,3 +1186,31 @@ def test_struct_eq_missing_outer_validity_19156(

assert_series_equal(l.eq_missing(r), pl.Series([True, False]))
assert_series_equal(l.ne_missing(r), pl.Series([False, True]))


def test_struct_field_list_eval_17356() -> None:
df = pl.DataFrame(
{
"items": [
[
{"name": "John", "age": 30, "car": None},
],
[
{"name": "Alice", "age": 65, "car": "Volvo"},
],
]
}
)

assert df.select(
pl.col("items").list.eval(
pl.element().struct.with_fields(
pl.field("name").str.to_uppercase(), pl.field("car").fill_null("Mazda")
)
)
).to_dict(as_series=False) == {
"items": [
[{"name": "JOHN", "age": 30, "car": "Mazda"}],
[{"name": "ALICE", "age": 65, "car": "Mazda"}],
],
}

0 comments on commit 7be7f06

Please sign in to comment.