From 306ad568881db3d9b1451bf790503bfd6bcc3640 Mon Sep 17 00:00:00 2001 From: Jeroen van Zundert Date: Sun, 16 Apr 2023 18:17:57 +0100 Subject: [PATCH 1/2] fix(python,rust): Fix DataFrame.sum returning empty column names --- py-polars/tests/unit/test_df.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/py-polars/tests/unit/test_df.py b/py-polars/tests/unit/test_df.py index b91c52929080..ea79cc227123 100644 --- a/py-polars/tests/unit/test_df.py +++ b/py-polars/tests/unit/test_df.py @@ -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) From 9b65cb176d3c812e216e653889cec328f678f287 Mon Sep 17 00:00:00 2001 From: Jeroen van Zundert Date: Sun, 16 Apr 2023 18:18:51 +0100 Subject: [PATCH 2/2] Fix previous commit --- polars/polars-core/src/series/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polars/polars-core/src/series/mod.rs b/polars/polars-core/src/series/mod.rs index 0e266b48e7d5..78968cd2a5cb 100644 --- a/polars/polars-core/src/series/mod.rs +++ b/polars/polars-core/src/series/mod.rs @@ -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();