polars_core/frame/column/
compare.rsuse polars_error::PolarsResult;
use super::{BooleanChunked, ChunkCompareEq, ChunkCompareIneq, ChunkExpandAtIndex, Column, Series};
macro_rules! column_element_wise_broadcasting {
($lhs:expr, $rhs:expr, $op:expr) => {
match ($lhs, $rhs) {
(Column::Series(lhs), Column::Series(rhs)) => $op(lhs, rhs),
(Column::Series(lhs), Column::Scalar(rhs)) => $op(lhs, &rhs.as_single_value_series()),
(Column::Scalar(lhs), Column::Series(rhs)) => $op(&lhs.as_single_value_series(), rhs),
(Column::Scalar(lhs), Column::Scalar(rhs)) => {
$op(&lhs.as_single_value_series(), &rhs.as_single_value_series()).map(|ca| {
if ca.len() == 0 {
ca
} else {
ca.new_from_index(0, lhs.len())
}
})
},
}
};
}
impl ChunkCompareEq<&Column> for Column {
type Item = PolarsResult<BooleanChunked>;
#[inline]
fn equal(&self, rhs: &Column) -> PolarsResult<BooleanChunked> {
column_element_wise_broadcasting!(self, rhs, <Series as ChunkCompareEq<&Series>>::equal)
}
#[inline]
fn equal_missing(&self, rhs: &Column) -> PolarsResult<BooleanChunked> {
column_element_wise_broadcasting!(
self,
rhs,
<Series as ChunkCompareEq<&Series>>::equal_missing
)
}
#[inline]
fn not_equal(&self, rhs: &Column) -> PolarsResult<BooleanChunked> {
column_element_wise_broadcasting!(self, rhs, <Series as ChunkCompareEq<&Series>>::not_equal)
}
#[inline]
fn not_equal_missing(&self, rhs: &Column) -> PolarsResult<BooleanChunked> {
column_element_wise_broadcasting!(
self,
rhs,
<Series as ChunkCompareEq<&Series>>::not_equal_missing
)
}
}
impl ChunkCompareIneq<&Column> for Column {
type Item = PolarsResult<BooleanChunked>;
#[inline]
fn gt(&self, rhs: &Column) -> PolarsResult<BooleanChunked> {
column_element_wise_broadcasting!(self, rhs, <Series as ChunkCompareIneq<&Series>>::gt)
}
#[inline]
fn gt_eq(&self, rhs: &Column) -> PolarsResult<BooleanChunked> {
column_element_wise_broadcasting!(self, rhs, <Series as ChunkCompareIneq<&Series>>::gt_eq)
}
#[inline]
fn lt(&self, rhs: &Column) -> PolarsResult<BooleanChunked> {
column_element_wise_broadcasting!(self, rhs, <Series as ChunkCompareIneq<&Series>>::lt)
}
#[inline]
fn lt_eq(&self, rhs: &Column) -> PolarsResult<BooleanChunked> {
column_element_wise_broadcasting!(self, rhs, <Series as ChunkCompareIneq<&Series>>::lt_eq)
}
}