Skip to content

Commit

Permalink
Fix slicing of ChunkedArray if end index == array length (#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
robert3005 authored Aug 20, 2024
1 parent ee1f7ae commit e57f0bd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion vortex-array/src/array/chunked/compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl CastFn for ChunkedArray {
impl CompareFn for ChunkedArray {
fn compare(&self, array: &Array, operator: Operator) -> VortexResult<Array> {
let mut idx = 0;
let mut compare_chunks = Vec::default();
let mut compare_chunks = Vec::with_capacity(self.nchunks());

for chunk in self.chunks() {
let sliced = slice(array, idx, idx + chunk.len())?;
Expand Down
13 changes: 12 additions & 1 deletion vortex-array/src/array/chunked/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,13 @@ impl ChunkedArray {
panic!("Search sorted failed in find_chunk_idx: {}", err);
});
let index_chunk = match search_result {
SearchResult::Found(i) => i,
SearchResult::Found(i) => {
if i == self.nchunks() {
i - 1
} else {
i
}
}
SearchResult::NotFound(i) => i - 1,
};
let chunk_start = &scalar_at(&self.chunk_ends(), index_chunk)
Expand Down Expand Up @@ -242,6 +248,11 @@ mod test {
assert_equal_slices(slice(chunked_array().array(), 7, 8).unwrap(), &[8u64]);
}

#[test]
pub fn slice_exactly_end() {
assert_equal_slices(slice(chunked_array().array(), 6, 9).unwrap(), &[7u64, 8, 9]);
}

#[test]
fn test_scalar_subtract() {
let chunked = chunked_array();
Expand Down
2 changes: 1 addition & 1 deletion vortex-array/src/compute/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn check_slice_bounds(array: &Array, start: usize, stop: usize) -> VortexResult<
vortex_bail!(OutOfBounds: stop, 0, array.len());
}
if start > stop {
vortex_bail!("start ({}) must be <= stop ({})", start, stop);
vortex_bail!("start ({start}) must be <= stop ({stop})");
}
Ok(())
}

0 comments on commit e57f0bd

Please sign in to comment.