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

perf(rust, python): remove O^2 behavior in melt #7003

Merged
merged 2 commits into from
Feb 18, 2023
Merged
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
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