Skip to content

Commit

Permalink
fix: Fix split_chunks for nested dtypes (#16493)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored May 26, 2024
1 parent cd04f3d commit d265cd1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/polars-arrow/src/record_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<A: AsRef<dyn Array>> RecordBatchT<A> {
.any(|array| array.len() != len)
{
polars_bail!(ComputeError:
"Chunk require all its arrays to have an equal number of rows".to_string(),
"RecordBatch requires all its arrays to have an equal number of rows".to_string(),
);
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/polars-core/src/frame/chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ impl DataFrame {
.get_columns()
.iter()
.map(|s| {
Series::from_chunks_and_dtype_unchecked(
s.name(),
vec![s.chunks()[i].clone()],
s.dtype(),
)
if s.n_chunks() == 1 {
s.clone()
} else {
s.replace_with_chunk(s.chunks()[i].clone())
}
})
.collect::<Vec<_>>();

Expand Down
26 changes: 26 additions & 0 deletions crates/polars-core/src/series/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,32 @@ impl Series {
ca.chunks_mut()
}

/// Create a `Series` of the same data type with all chunks replaced.
/// # Safety
/// These chunks should align with the data-type
pub unsafe fn replace_chunks(&self, chunks: Vec<ArrayRef>) -> Self {
let mut new = self.clear();
// Assign mut so we go through arc only once.
let mut_new = new._get_inner_mut();
*mut_new.chunks_mut() = chunks;
mut_new.compute_len();
new
}

/// Create a `Series` of the same data type with all chunks replaced.
/// # Safety
/// This chunk should align with the data-type
pub unsafe fn replace_with_chunk(&self, chunk: ArrayRef) -> Self {
let mut new = self.clear();
// Assign mut so we go through arc only once.
let mut_new = new._get_inner_mut();
let chunks = mut_new.chunks_mut();
chunks.clear();
chunks.push(chunk);
mut_new.compute_len();
new
}

pub fn is_sorted_flag(&self) -> IsSorted {
if self.len() <= 1 {
return IsSorted::Ascending;
Expand Down

0 comments on commit d265cd1

Please sign in to comment.