Skip to content

Commit

Permalink
fix(python,rust): Fix DataFrame.sum returning empty column names (#8283)
Browse files Browse the repository at this point in the history
  • Loading branch information
zundertj authored Apr 16, 2023
1 parent 06289aa commit abed1ee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion polars/polars-core/src/series/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ impl Series {
if self.is_empty()
&& (self.dtype().is_numeric() || matches!(self.dtype(), DataType::Boolean))
{
return Series::new("", [0])
return Series::new(self.name(), [0])
.cast(self.dtype())
.unwrap()
.sum_as_series();
Expand Down
8 changes: 8 additions & 0 deletions py-polars/tests/unit/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -3782,3 +3782,11 @@ def test_window_deadlock() -> None:
pl.col("random").implode().over("names").alias("random/name"),
]
)


def test_sum_empty_column_names() -> None:
df = pl.DataFrame({"x": [], "y": []}, schema={"x": pl.Boolean, "y": pl.Boolean})
expected = pl.DataFrame(
{"x": [0], "y": [0]}, schema={"x": pl.UInt32, "y": pl.UInt32}
)
assert_frame_equal(df.sum(), expected)

0 comments on commit abed1ee

Please sign in to comment.