Skip to content

Commit

Permalink
Remove duplicate bound check in the function shift (#1409)
Browse files Browse the repository at this point in the history
Signed-off-by: remzi <13716567376yh@gmail.com>
  • Loading branch information
HaoYang670 committed Mar 11, 2022
1 parent 0d24777 commit fcb8950
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions arrow/src/compute/kernels/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use crate::{
array::{make_array, new_null_array},
compute::concat,
};
use num::{abs, clamp};
use num::abs;
use num::traits::clamp_min;

/// Shifts array by defined number of items (to left or right)
/// A positive value for `offset` shifts the array to the right
Expand Down Expand Up @@ -63,7 +64,7 @@ pub fn shift(array: &dyn Array, offset: i64) -> Result<ArrayRef> {
} else if offset == i64::MIN || abs(offset) >= value_len {
Ok(new_null_array(array.data_type(), array.len()))
} else {
let slice_offset = clamp(-offset, 0, value_len) as usize;
let slice_offset = clamp_min(-offset, 0) as usize;
let length = array.len() - abs(offset) as usize;
let slice = array.slice(slice_offset, length);

Expand Down

0 comments on commit fcb8950

Please sign in to comment.