-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat[rust]: groupby numeric list columns (#4919)
- Loading branch information
Showing
25 changed files
with
208 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use arrow::array::{ListArray, PrimitiveArray}; | ||
use arrow::bitmap::Bitmap; | ||
use arrow::datatypes::PhysicalType::Primitive; | ||
use arrow::types::NativeType; | ||
|
||
use crate::error::PolarsError; | ||
use crate::utils::with_match_primitive_type; | ||
|
||
unsafe fn bytes_iter<'a, T: NativeType>( | ||
values: &'a [T], | ||
offsets: &'a [i64], | ||
validity: Option<&'a Bitmap>, | ||
) -> impl ExactSizeIterator<Item = Option<&'a [u8]>> { | ||
let mut start = offsets[0] as usize; | ||
offsets[1..].iter().enumerate().map(move |(i, end)| { | ||
let end = *end as usize; | ||
let out = values.get_unchecked(start..end); | ||
start = end; | ||
|
||
let data = out.as_ptr() as *const u8; | ||
let out = std::slice::from_raw_parts(data, std::mem::size_of::<T>() * out.len()); | ||
match validity { | ||
None => Some(out), | ||
Some(validity) => { | ||
if validity.get_bit_unchecked(i) { | ||
Some(out) | ||
} else { | ||
None | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
|
||
pub fn numeric_list_bytes_iter( | ||
arr: &ListArray<i64>, | ||
) -> Result<Box<dyn ExactSizeIterator<Item = Option<&[u8]>> + '_>, PolarsError> { | ||
let values = arr.values(); | ||
if values.null_count() > 0 { | ||
return Err(PolarsError::ComputeError( | ||
"only allowed for child arrays without nulls".into(), | ||
)); | ||
} | ||
let offsets = arr.offsets().as_slice(); | ||
let validity = arr.validity(); | ||
|
||
if let Primitive(primitive) = values.data_type().to_physical_type() { | ||
with_match_primitive_type!(primitive, |$T| { | ||
let arr: &PrimitiveArray<$T> = values.as_any().downcast_ref().unwrap(); | ||
let values = arr.values(); | ||
let iter = unsafe { bytes_iter(values.as_slice(), offsets, validity) }; | ||
Ok(Box::new(iter)) | ||
}) | ||
} else { | ||
Err(PolarsError::ComputeError( | ||
"only allowed for numeric child arrays".into(), | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.