From ef43739ecb7fa0a03843d100027ead651ecdc7e5 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 24 Sep 2024 14:02:16 -0400 Subject: [PATCH] Handle addition and multipliction cases where the rhs Series is numeric and the ls is a list. --- crates/polars-core/src/series/arithmetic/borrowed.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/polars-core/src/series/arithmetic/borrowed.rs b/crates/polars-core/src/series/arithmetic/borrowed.rs index 26c8282184be..a40e5dd6d2d5 100644 --- a/crates/polars-core/src/series/arithmetic/borrowed.rs +++ b/crates/polars-core/src/series/arithmetic/borrowed.rs @@ -532,6 +532,12 @@ impl Add for &Series { (DataType::Struct(_), DataType::Struct(_)) => { _struct_arithmetic(self, rhs, |a, b| a.add(b)) }, + (left_dtype, DataType::List(_)) if left_dtype.is_numeric() => { + // Lists have implementation logic for rhs numeric: + let mut result = (rhs + self)?; + result.rename(self.name().clone()); + Ok(result) + }, _ => { let (lhs, rhs) = coerce_lhs_rhs(self, rhs)?; lhs.add_to(rhs.as_ref()) @@ -584,6 +590,12 @@ impl Mul for &Series { let out = rhs.multiply(self)?; Ok(out.with_name(self.name().clone())) }, + (left_dtype, DataType::List(_)) if left_dtype.is_numeric() => { + // Lists have implementation logic for rhs numeric: + let mut result = (rhs * self)?; + result.rename(self.name().clone()); + Ok(result) + }, _ => { let (lhs, rhs) = coerce_lhs_rhs(self, rhs)?; lhs.multiply(rhs.as_ref())