Skip to content

Commit

Permalink
Handle addition and multipliction cases where the rhs Series is numer…
Browse files Browse the repository at this point in the history
…ic and the ls is a list.
  • Loading branch information
pythonspeed committed Sep 24, 2024
1 parent 835f9fa commit ef43739
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/polars-core/src/series/arithmetic/borrowed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit ef43739

Please sign in to comment.