pub fn if_then_else(
    predicate: &BooleanArray,
    lhs: &dyn Array,
    rhs: &dyn Array
) -> Result<Box<dyn Array>>
Available on crate feature compute_if_then_else only.
Expand description

Returns the values from lhs if the predicate is true or from the rhs if the predicate is false Returns None if the predicate is None.

Example

use arrow2::compute::if_then_else::if_then_else;
use arrow2::array::{Int32Array, BooleanArray};

let lhs = Int32Array::from_slice(&[1, 2, 3]);
let rhs = Int32Array::from_slice(&[4, 5, 6]);
let predicate = BooleanArray::from(&[Some(true), None, Some(false)]);
let result = if_then_else(&predicate, &lhs, &rhs)?;

let expected = Int32Array::from(&[Some(1), None, Some(6)]);

assert_eq!(expected, result.as_ref());