Skip to content

Commit

Permalink
fix(rust, python): fix coalesce expreession expansion (#5521)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Nov 16, 2022
1 parent 49058bb commit 35c53af
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions polars/polars-lazy/polars-plan/src/dsl/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,7 @@ pub fn coalesce(exprs: &[Expr]) -> Expr {
options: FunctionOptions {
collect_groups: ApplyOptions::ApplyGroups,
cast_to_supertypes: true,
input_wildcard_expansion: true,
..Default::default()
},
}
Expand Down
3 changes: 2 additions & 1 deletion py-polars/polars/internals/lazy_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2093,7 +2093,8 @@ def arg_where(
def coalesce(
exprs: Sequence[
pli.Expr | str | date | datetime | timedelta | int | float | bool | pli.Series
],
]
| pli.Expr,
) -> pli.Expr:
"""
Folds the expressions from left to right, keeping the first non-null value.
Expand Down
3 changes: 3 additions & 0 deletions py-polars/tests/unit/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ def test_coalesce() -> None:
assert df.select(pl.coalesce(["a", "b", "c", 10])).to_dict(False) == {
"a": [1.0, 2.0, 3.0, 10.0]
}
assert df.select(pl.coalesce(pl.col(["a", "b", "c"]))).to_dict(False) == {
"a": [1.0, 2.0, 3.0, None]
}


def test_ones_zeros() -> None:
Expand Down

0 comments on commit 35c53af

Please sign in to comment.