Skip to content

Commit b6983cf

Browse files
authored
Merge pull request #532 from nikitinas/fix-rename-performance
Fix performance problem in `rename` implementation
2 parents 348e9ab + 046cd0c commit b6983cf

File tree

1 file changed

+3
-3
lines changed
  • core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api

1 file changed

+3
-3
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/rename.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ internal fun <T, C> RenameClause<T, C>.renameImpl(newNames: Array<out String>):
2222
internal fun <T, C> RenameClause<T, C>.renameImpl(transform: (ColumnWithPath<C>) -> String): DataFrame<T> {
2323
// get all selected columns and their paths
2424
val selectedColumnsWithPath = df.getColumnsWithPaths(columns)
25-
.associateBy { it.data }
25+
.associateBy { it.path }
2626
// gather a tree of all columns where the nodes will be renamed
2727
val tree = df.getColumnsWithPaths { all().rec() }.collectTree()
2828

2929
// perform rename in nodes
30-
tree.allChildrenNotNull().forEach { node ->
30+
tree.allChildrenNotNull().map { it to it.pathFromRoot() }.forEach { (node, originalPath) ->
3131
// Check if the current node/column is a selected column and, if so, get its ColumnWithPath
32-
val column = selectedColumnsWithPath[node.data] ?: return@forEach
32+
val column = selectedColumnsWithPath[originalPath] ?: return@forEach
3333
// Use the found selected ColumnWithPath to query for the new name
3434
val newColumnName = transform(column)
3535
node.name = newColumnName

0 commit comments

Comments
 (0)