From e09cd0b490ae9f39e5d1524fbe84f48eaeda863b Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Fri, 6 Sep 2024 12:00:23 +0100 Subject: [PATCH] fix(rust): Ensure result name of pow matches schema in grouped context (#18533) --- crates/polars-plan/src/dsl/function_expr/pow.rs | 5 ++++- py-polars/tests/unit/operations/test_group_by.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/polars-plan/src/dsl/function_expr/pow.rs b/crates/polars-plan/src/dsl/function_expr/pow.rs index a12ef242f435..5336220d1ace 100644 --- a/crates/polars-plan/src/dsl/function_expr/pow.rs +++ b/crates/polars-plan/src/dsl/function_expr/pow.rs @@ -37,12 +37,15 @@ where ChunkedArray: 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( diff --git a/py-polars/tests/unit/operations/test_group_by.py b/py-polars/tests/unit/operations/test_group_by.py index 3a5436b91299..09864b329c22 100644 --- a/py-polars/tests/unit/operations/test_group_by.py +++ b/py-polars/tests/unit/operations/test_group_by.py @@ -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]], }