Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicate bound check in the function shift #1409

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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