Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mcrumiller committed Jan 19, 2025
1 parent fe2014f commit 5a22cac
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions crates/polars-ops/src/series/ops/horizontal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,22 +242,19 @@ 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()))? {
DataType::Boolean => IDX_DTYPE,
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() {
Expand All @@ -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(
Expand All @@ -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())
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 5a22cac

Please sign in to comment.