Skip to content

Commit

Permalink
rechunk in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Oct 15, 2021
1 parent 59386ea commit 47ad9b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 8 additions & 1 deletion polars/polars-core/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ impl DataFrame {
self
}

/// Aggregate all the chunks in the DataFrame to a single chunk in parallel.
/// This may lead to more peak memory consumption.
pub fn as_single_chunk_par(&mut self) -> &mut Self {
self.columns = self.columns.par_iter().map(|s| s.rechunk()).collect();
self
}

/// Ensure all the chunks in the DataFrame are aligned.
pub fn rechunk(&mut self) -> &mut Self {
let hb = RandomState::default();
Expand Down Expand Up @@ -246,7 +253,7 @@ impl DataFrame {
{
self
} else {
self.as_single_chunk()
self.as_single_chunk_par()
}
}

Expand Down
6 changes: 5 additions & 1 deletion polars/polars-io/src/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,11 @@ where
// Important that this rechunk is never done in parallel.
// As that leads to great memory overhead.
if rechunk && df.n_chunks()? > 1 {
df.as_single_chunk();
if self.low_memory {
df.as_single_chunk();
} else {
df.as_single_chunk_par();
}
}
#[cfg(feature = "temporal")]
if self.parse_dates {
Expand Down

0 comments on commit 47ad9b5

Please sign in to comment.