pub fn filter(array: &dyn Array, mask: &Mask) -> VortexResult<ArrayRef>
Expand description
Keep only the elements for which the corresponding mask value is true.
§Examples
use vortex_array::{Array, IntoArray};
use vortex_array::arrays::{BoolArray, PrimitiveArray};
use vortex_array::compute::{ filter, mask};
use vortex_mask::Mask;
use vortex_scalar::Scalar;
let array =
PrimitiveArray::from_option_iter([Some(0i32), None, Some(1i32), None, Some(2i32)]);
let mask = Mask::try_from(
&BoolArray::from_iter([true, false, false, false, true]),
)
.unwrap();
let filtered = filter(array.as_ref(), &mask).unwrap();
assert_eq!(filtered.len(), 2);
assert_eq!(filtered.scalar_at(0).unwrap(), Scalar::from(Some(0_i32)));
assert_eq!(filtered.scalar_at(1).unwrap(), Scalar::from(Some(2_i32)));
§Panics
The predicate
must receive an Array with type non-nullable bool, and will panic if this is
not the case.