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

Fix SearchSorted on sliced sparse array #411

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions vortex-array/src/array/sparse/compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,16 @@ impl SearchSortedFn for SparseArray {
search_sorted(&self.values(), value.clone(), side).and_then(|sr| match sr {
SearchResult::Found(i) => {
let index: usize = scalar_at(&self.indices(), i)?.as_ref().try_into().unwrap();
Ok(SearchResult::Found(index))
Ok(SearchResult::Found(index - self.indices_offset()))
}
SearchResult::NotFound(i) => {
let index: usize = scalar_at(&self.indices(), if i == 0 { 0 } else { i - 1 })?
.as_ref()
.try_into()
.unwrap();
Ok(SearchResult::NotFound(if i == 0 {
index
} else {
index + 1
}))
Ok(SearchResult::NotFound(
if i == 0 { index } else { index + 1 } - self.indices_offset(),
))
}
})
}
Expand All @@ -71,6 +69,7 @@ mod test {
use crate::array::primitive::PrimitiveArray;
use crate::array::sparse::SparseArray;
use crate::compute::search_sorted::{search_sorted, SearchResult, SearchSortedSide};
use crate::compute::slice::slice;
use crate::validity::Validity;
use crate::{Array, IntoArray};

Expand Down Expand Up @@ -102,4 +101,13 @@ mod test {
let res = search_sorted(&array(), 44, SearchSortedSide::Left).unwrap();
assert_eq!(res, SearchResult::Found(9));
}

#[test]
pub fn search_sliced() {
let array = slice(&array(), 7, 20).unwrap();
assert_eq!(
search_sorted(&array, 22, SearchSortedSide::Left).unwrap(),
SearchResult::NotFound(2)
);
}
}
Loading