Skip to content

Commit

Permalink
perf(rust, python): remove O^2 behavior in melt (#7003)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Feb 18, 2023
1 parent 0be4cc1 commit 84e53aa
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion polars/polars-core/src/frame/explode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,11 @@ impl DataFrame {

for value_column_name in &value_vars {
variable_col.extend_trusted_len_values(std::iter::repeat(value_column_name).take(len));
let value_col = self.column(value_column_name)?.cast(&st)?;
// ensure we go via the schema so we are O(1)
// self.column() is linear
// together with this loop that would make it O^2 over value_vars
let (pos, _name, _dtype) = schema.try_get_full(value_column_name)?;
let value_col = self.columns[pos].cast(&st).unwrap();
values.extend_from_slice(value_col.chunks())
}
let values_arr = concatenate_owned_unchecked(&values)?;
Expand Down

0 comments on commit 84e53aa

Please sign in to comment.