diff --git a/crates/polars-plan/src/plans/functions/rename.rs b/crates/polars-plan/src/plans/functions/rename.rs index 7a58101e3731..4205fce095c5 100644 --- a/crates/polars-plan/src/plans/functions/rename.rs +++ b/crates/polars-plan/src/plans/functions/rename.rs @@ -5,10 +5,18 @@ pub(super) fn rename_impl( existing: &[PlSmallStr], new: &[PlSmallStr], ) -> PolarsResult { - let positions = existing - .iter() - .map(|old| df.get_column_index(old)) - .collect::>(); + let positions = if existing.len() > 1 && df.get_columns().len() > 10 { + let schema = df.schema(); + existing + .iter() + .map(|old| schema.get_full(old).map(|(idx, _, _)| idx)) + .collect::>() + } else { + existing + .iter() + .map(|old| df.get_column_index(old)) + .collect::>() + }; for (pos, name) in positions.iter().zip(new.iter()) { // the column might be removed due to projection pushdown