diff --git a/crates/polars-ops/src/series/ops/horizontal.rs b/crates/polars-ops/src/series/ops/horizontal.rs index 75a69201909..530fb861a71 100644 --- a/crates/polars-ops/src/series/ops/horizontal.rs +++ b/crates/polars-ops/src/series/ops/horizontal.rs @@ -242,9 +242,8 @@ pub fn sum_horizontal( // If we have any null columns and null strategy is not `Ignore`, we can return immediately. let num_cols = non_null_cols.len(); - let name = columns[0].name(); if num_cols == 0 { - return Ok(Some(columns[0].clone().with_name(name.clone()))); + return Ok(Some(columns[0].clone())); } else if !ignore_nulls && non_null_cols.len() < columns.len() { // We must determine the correct return dtype. let return_dtype = match dtypes_to_supertype(non_null_cols.iter().map(|c| c.dtype()))? { @@ -252,12 +251,10 @@ pub fn sum_horizontal( dt => dt, }; return Ok(Some(Column::full_null( - name.clone(), + columns[0].name().clone(), columns[0].len(), &return_dtype, ))); - } else if !ignore_nulls && non_null_cols.len() < columns.len() { - return null_with_supertype(non_null_cols, false); } match non_null_cols.len() { @@ -266,7 +263,7 @@ pub fn sum_horizontal( Ok(None) } else { // all columns are null dtype, so result is null dtype - Ok(Some(columns[0].clone().with_name(name.clone()))) + Ok(Some(columns[0].clone())) } }, 1 => Ok(Some( @@ -275,7 +272,6 @@ pub fn sum_horizontal( } else { non_null_cols[0].clone() })? - .with_name(name.clone()) .into(), )), 2 => sum_fn(non_null_cols[0].clone(), non_null_cols[1].clone()) @@ -357,7 +353,7 @@ pub fn mean_horizontal( if !ignore_nulls && dtype == &DataType::Null { // The presence of a single null column guarantees the output is all-null. return null_with_supertype(columns, true); - } else if !(dtype.is_numeric() + } else if !(dtype.is_primitive_numeric() || dtype.is_decimal() || dtype.is_bool() || dtype.is_temporal()