Skip to content

Commit

Permalink
fix(rust): Ensure result name of pow matches schema in grouped context (
Browse files Browse the repository at this point in the history
  • Loading branch information
wence- authored Sep 6, 2024
1 parent e94ada3 commit e09cd0b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion crates/polars-plan/src/dsl/function_expr/pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ where
ChunkedArray<T>: IntoSeries,
{
if (base.len() == 1) && (exponent.len() != 1) {
let name = base.name();
let base = base
.get(0)
.ok_or_else(|| polars_err!(ComputeError: "base is null"))?;

Ok(Some(
unary_elementwise_values(exponent, |exp| Pow::pow(base, exp)).into_series(),
unary_elementwise_values(exponent, |exp| Pow::pow(base, exp))
.into_series()
.with_name(name.clone()),
))
} else {
Ok(Some(
Expand Down
2 changes: 1 addition & 1 deletion py-polars/tests/unit/operations/test_group_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ def test_group_by_apply_first_input_is_literal() -> None:
pow = df.group_by("g").agg(2 ** pl.col("x"))
assert pow.sort("g").to_dict(as_series=False) == {
"g": [1, 2],
"x": [[2.0, 4.0], [8.0, 16.0, 32.0]],
"literal": [[2.0, 4.0], [8.0, 16.0, 32.0]],
}


Expand Down

0 comments on commit e09cd0b

Please sign in to comment.