pub fn filter(array: &dyn Array, filter: &BooleanArray) -> Result<Box<dyn Array>> {
    let iter = SlicesIterator::new(filter.values());

    match array.data_type() {
        DataType::UInt8 => {
            dyn_filter!(u8, array, iter)
        }
        DataType::UInt16 => {
            dyn_filter!(u16, array, iter)
        }
        DataType::UInt32 => {
            dyn_filter!(u32, array, iter)
        }
        DataType::UInt64 => {
            dyn_filter!(u64, array, iter)
        }
        DataType::Int8 => {
            dyn_filter!(i8, array, iter)
        }
        DataType::Int16 => {
            dyn_filter!(i16, array, iter)
        }
        DataType::Int32
        | DataType::Date32
        | DataType::Time32(_)
        | DataType::Interval(IntervalUnit::YearMonth) => {
            dyn_filter!(i32, array, iter)
        }
        DataType::Int64
        | DataType::Date64
        | DataType::Time64(_)
        | DataType::Timestamp(_, _)
        | DataType::Duration(_) => {
            dyn_filter!(i64, array, iter)
        }
        DataType::Interval(IntervalUnit::DayTime) => {
            dyn_filter!(days_ms, array, iter)
        }
        DataType::Float32 => {
            dyn_filter!(f32, array, iter)
        }
        DataType::Float64 => {
            dyn_filter!(f64, array, iter)
        }
        _ => {
            let mut mutable = make_growable(&[array], false, iter.slots());
            iter.for_each(|(start, len)| mutable.extend(0, start, len));
            Ok(mutable.to_box())
        }
    }
}
/// Filters an [Array], returning elements matching the filter (i.e. where the values are true).
/// WARNING: the nulls of `filter` are ignored and the value on its slot is considered.
/// Therefore, it is considered undefined behavior to pass `filter` with null values.
/// # Example
/// ```rust
/// # use arrow2::array::{Int32Array, Primitive, BooleanArray};
/// # use arrow2::datatypes::DataType;
/// # use arrow2::error::Result;
/// # use arrow2::compute::filter::filter;
/// # fn main() -> Result<()> {
/// let array = Primitive::from_slice(&vec![5, 6, 7, 8, 9]).to(DataType::Int32);
/// let filter_array = BooleanArray::from_slice(&vec![true, false, false, true, false]);
/// let c = filter(&array, &filter_array)?;
/// let c = c.as_any().downcast_ref::<Int32Array>().unwrap();
/// assert_eq!(c, &Primitive::from_slice(vec![5, 8]).to(DataType::Int32));
/// # Ok(())
/// # }
/// ```
Filters an [Array], returning elements matching the filter .
WARNING: the nulls of `filter` are ignored and the value on its slot is considered.
Therefore, it is considered undefined behavior to pass `filter` with null values.
Filters an [ Array ] returning elements matching the filter . WARNING : the nulls of ` filter ` are ignored and the value on its slot is considered . Therefore it is considered undefined behavior to pass ` filter ` with null values .
pub fn filter(array: &dyn Array, filter: &BooleanArray) -> Result<Box<dyn Array>> {
    let iter = SlicesIterator::new(filter.values());
    match array.data_type() {
        DataType::UInt8 => {
            dyn_filter!(u8, array, iter)
        }
        DataType::UInt16 => {
            dyn_filter!(u16, array, iter)
        }
        DataType::UInt32 => {
            dyn_filter!(u32, array, iter)
        }
        DataType::UInt64 => {
            dyn_filter!(u64, array, iter)
        }
        DataType::Int8 => {
            dyn_filter!(i8, array, iter)
        }
        DataType::Int16 => {
            dyn_filter!(i16, array, iter)
        }
        DataType::Int32
        | DataType::Date32
        | DataType::Time32(_)
        | DataType::Interval(IntervalUnit::YearMonth) => {
            dyn_filter!(i32, array, iter)
        }
        DataType::Int64
        | DataType::Date64
        | DataType::Time64(_)
        | DataType::Timestamp(_, _)
        | DataType::Duration(_) => {
            dyn_filter!(i64, array, iter)
        }
        DataType::Interval(IntervalUnit::DayTime) => {
            dyn_filter!(days_ms, array, iter)
        }
        DataType::Float32 => {
            dyn_filter!(f32, array, iter)
        }
        DataType::Float64 => {
            dyn_filter!(f64, array, iter)
        }
        _ => {
            let mut mutable = make_growable(&[array], false, iter.slots());
            iter.for_each(|(start, len)| mutable.extend(0, start, len));
            Ok(mutable.to_box())
        }
    }
}
pub fn filter ( array : & dyn Array , filter : & BooleanArray ) -> Result < Box < dyn Array > > { let iter = SlicesIterator :: new ( filter . values ( ) ) ; match array . data_type ( ) { DataType :: UInt8 => { dyn_filter ! ( u8 array iter ) } DataType :: UInt16 => { dyn_filter ! ( u16 array iter ) } DataType :: UInt32 => { dyn_filter ! ( u32 array iter ) } DataType :: UInt64 => { dyn_filter ! ( u64 array iter ) } DataType :: Int8 => { dyn_filter ! ( i8 array iter ) } DataType :: Int16 => { dyn_filter ! ( i16 array iter ) } DataType :: Int32 | DataType :: Date32 | DataType :: Time32 ( _ ) | DataType :: Interval ( IntervalUnit :: YearMonth ) => { dyn_filter ! ( i32 array iter ) } DataType :: Int64 | DataType :: Date64 | DataType :: Time64 ( _ ) | DataType :: Timestamp ( _ , _ ) | DataType :: Duration ( _ ) => { dyn_filter ! ( i64 array iter ) } DataType :: Interval ( IntervalUnit :: DayTime ) => { dyn_filter ! ( days_ms array iter ) } DataType :: Float32 => { dyn_filter ! ( f32 array iter ) } DataType :: Float64 => { dyn_filter ! ( f64 array iter ) } _ => { let mut mutable = make_growable ( & [ array ] , false , iter . slots ( ) ) ; iter . for_each ( | ( start , len ) | mutable . extend ( 0 , start , len ) ) ; Ok ( mutable . to_box ( ) ) } } }
Filters an [Array], returning elements matching the filter (i.e.
Filters an [ Array ] returning elements matching the filter ( i . e .
array
&dyn Array
filter
&BooleanArray
array
&dyn Array
filter
&BooleanArray
example
None
use arrow2::array::{int32array, primitive, booleanarray};
None
use arrow2::datatypes::datatype;
None
use arrow2::error::result;
None
use arrow2::compute::filter::filter;
None
fn main() -> result<()> {
let array = Primitive::from_slice(&vec![5, 6, 7, 8, 9]).to(DataType::Int32);
let filter_array = BooleanArray::from_slice(&vec![true, false, false, true, false]);
let c = filter(&array, &filter_array)?;
let c = c.as_any().downcast_ref::().unwrap();
assert_eq!(c, &Primitive::from_slice(vec![5, 8]).to(DataType::Int32)).
let array = Primitive :: from_slice ( &vec! [ 5 6 7 8 9 ] ) . to ( DataType :: Int32 ) ; let filter_array = BooleanArray :: from_slice ( &vec! [ true false false true false ] ) ; let c = filter ( &array &filter_array ) ? ; let c = c . as_any () . downcast_ref :: () . unwrap () ; assert_eq! ( c &Primitive :: from_slice ( vec! [ 5 8 ] ) . to ( DataType :: Int32 )) .
ok(())
None
}
None