From 19b52cb41b1a3dc09f2359383b010fb4a46c9741 Mon Sep 17 00:00:00 2001 From: coastalwhite Date: Thu, 19 Sep 2024 08:06:32 +0200 Subject: [PATCH] allow broadcasts --- crates/polars-core/src/series/comparison.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/polars-core/src/series/comparison.rs b/crates/polars-core/src/series/comparison.rs index b632880b50d4..bea981db89f1 100644 --- a/crates/polars-core/src/series/comparison.rs +++ b/crates/polars-core/src/series/comparison.rs @@ -10,7 +10,16 @@ macro_rules! impl_compare { let (lhs, rhs) = ($self, $rhs); validate_types(lhs.dtype(), rhs.dtype())?; - polars_ensure!(lhs.len() == rhs.len(), ShapeMismatch: "could not compare between two series of different length ({} != {})", lhs.len(), rhs.len()); + polars_ensure!( + lhs.len() == rhs.len() || + + // Broadcast + lhs.len() == 1 || + rhs.len() == 1, + ShapeMismatch: "could not compare between two series of different length ({} != {})", + lhs.len(), + rhs.len() + ); #[cfg(feature = "dtype-categorical")] match (lhs.dtype(), rhs.dtype()) {