diff --git a/crates/polars-core/src/frame/column/mod.rs b/crates/polars-core/src/frame/column/mod.rs index 585350c7627c..6e2a36be8b75 100644 --- a/crates/polars-core/src/frame/column/mod.rs +++ b/crates/polars-core/src/frame/column/mod.rs @@ -605,7 +605,7 @@ impl Column { Column::Partitioned(s) => series_agg(s.as_materialized_series(), groups).into_column(), Column::Scalar(s) => { if s.is_empty() { - return self.clone(); + return series_agg(s.as_materialized_series(), groups).into_column(); } // We utilize the aggregation on Series to see: diff --git a/py-polars/tests/unit/test_schema.py b/py-polars/tests/unit/test_schema.py index 44211da41858..7ebae8e22f01 100644 --- a/py-polars/tests/unit/test_schema.py +++ b/py-polars/tests/unit/test_schema.py @@ -336,3 +336,12 @@ def test_raise_subnodes_18787() -> None: pl.first().struct.field("a", "b").filter(pl.col("foo") == 1) ) ) + + +def test_scalar_agg_schema_20044() -> None: + assert ( + pl.DataFrame(None, schema={"a": pl.Int64, "b": pl.String, "c": pl.String}) + .with_columns(d=pl.col("a").max()) + .group_by("c") + .agg(pl.col("d").mean()) + ).schema == pl.Schema([("c", pl.String), ("d", pl.Float64)])