Function arrow::compute::kernels::window::shift [−][src]
pub fn shift(array: &dyn Array, offset: i64) -> Result<ArrayRef>
Expand description
Shifts array by defined number of items (to left or right)
A positive value for offset
shifts the array to the right
a negative value shifts the array to the left.
Examples
use arrow::array::Int32Array; use arrow::error::Result; use arrow::compute::shift; let a: Int32Array = vec![Some(1), None, Some(4)].into(); // shift array 1 element to the right let res = shift(&a, 1).unwrap(); let expected: Int32Array = vec![None, Some(1), None].into(); assert_eq!(res.as_ref(), &expected); // shift array 1 element to the left let res = shift(&a, -1).unwrap(); let expected: Int32Array = vec![None, Some(4), None].into(); assert_eq!(res.as_ref(), &expected); // shift array 0 element, although not recommended let res = shift(&a, 0).unwrap(); let expected: Int32Array = vec![Some(1), None, Some(4)].into(); assert_eq!(res.as_ref(), &expected); // shift array 3 element tot he right let res = shift(&a, 3).unwrap(); let expected: Int32Array = vec![None, None, None].into(); assert_eq!(res.as_ref(), &expected);