Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix empty scalar agg type #20051

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/polars-core/src/frame/column/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions py-polars/tests/unit/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Loading