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

Move zip and shift kernels to arrow-select #3201

Merged
merged 1 commit into from
Nov 26, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions arrow-select/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ pub mod concat;
pub mod filter;
pub mod interleave;
pub mod take;
pub mod window;
pub mod zip;
18 changes: 7 additions & 11 deletions arrow/src/compute/kernels/window.rs → arrow-select/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,18 @@

//! Defines windowing functions, like `shift`ing

use crate::array::{Array, ArrayRef};
use crate::error::Result;
use crate::{
array::{make_array, new_null_array},
compute::concat,
};
use crate::concat::concat;
use arrow_array::{make_array, new_null_array, Array, ArrayRef};
use arrow_schema::ArrowError;
use num::abs;

/// 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;
/// # use arrow_array::Int32Array;
/// # use arrow_select::window::shift;
///
/// let a: Int32Array = vec![Some(1), None, Some(4)].into();
///
Expand All @@ -56,7 +52,7 @@ use num::abs;
/// let expected: Int32Array = vec![None, None, None].into();
/// assert_eq!(res.as_ref(), &expected);
/// ```
pub fn shift(array: &dyn Array, offset: i64) -> Result<ArrayRef> {
pub fn shift(array: &dyn Array, offset: i64) -> Result<ArrayRef, ArrowError> {
let value_len = array.len() as i64;
if offset == 0 {
Ok(make_array(array.data_ref().clone()))
Expand Down Expand Up @@ -86,7 +82,7 @@ pub fn shift(array: &dyn Array, offset: i64) -> Result<ArrayRef> {
#[cfg(test)]
mod tests {
use super::*;
use crate::array::{Float64Array, Int32Array, Int32DictionaryArray};
use arrow_array::{Float64Array, Int32Array, Int32DictionaryArray};

#[test]
fn test_shift_neg() {
Expand Down
9 changes: 5 additions & 4 deletions arrow/src/compute/kernels/zip.rs → arrow-select/src/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
// specific language governing permissions and limitations
// under the License.

use crate::array::*;
use crate::compute::SlicesIterator;
use crate::error::{ArrowError, Result};
use crate::filter::SlicesIterator;
use arrow_array::*;
use arrow_data::transform::MutableArrayData;
use arrow_schema::ArrowError;

/// Zip two arrays by some boolean mask. Where the mask evaluates `true` values of `truthy`
/// are taken, where the mask evaluates `false` values of `falsy` are taken.
Expand All @@ -30,7 +31,7 @@ pub fn zip(
mask: &BooleanArray,
truthy: &dyn Array,
falsy: &dyn Array,
) -> Result<ArrayRef> {
) -> Result<ArrayRef, ArrowError> {
if truthy.data_type() != falsy.data_type() {
return Err(ArrowError::InvalidArgumentError(
"arguments need to have the same data type".into(),
Expand Down
4 changes: 1 addition & 3 deletions arrow/src/compute/kernels/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ pub mod regexp;
pub mod sort;
pub mod substring;
pub mod temporal;
pub mod window;
pub mod zip;

pub use arrow_cast::cast;
pub use arrow_cast::parse as cast_utils;
pub use arrow_select::{concat, filter, interleave, take};
pub use arrow_select::{concat, filter, interleave, take, window, zip};