Skip to content

Commit 0f4360b

Browse files
authored
perf: Improve rename performace for Lazy API (#18890)
1 parent 7bc6214 commit 0f4360b

File tree

1 file changed

+12
-4
lines changed
  • crates/polars-plan/src/plans/functions

1 file changed

+12
-4
lines changed

crates/polars-plan/src/plans/functions/rename.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@ pub(super) fn rename_impl(
55
existing: &[PlSmallStr],
66
new: &[PlSmallStr],
77
) -> PolarsResult<DataFrame> {
8-
let positions = existing
9-
.iter()
10-
.map(|old| df.get_column_index(old))
11-
.collect::<Vec<_>>();
8+
let positions = if existing.len() > 1 && df.get_columns().len() > 10 {
9+
let schema = df.schema();
10+
existing
11+
.iter()
12+
.map(|old| schema.get_full(old).map(|(idx, _, _)| idx))
13+
.collect::<Vec<_>>()
14+
} else {
15+
existing
16+
.iter()
17+
.map(|old| df.get_column_index(old))
18+
.collect::<Vec<_>>()
19+
};
1220

1321
for (pos, name) in positions.iter().zip(new.iter()) {
1422
// the column might be removed due to projection pushdown

0 commit comments

Comments
 (0)