dataframe icon indicating copy to clipboard operation
dataframe copied to clipboard

Replace With breaks if running on `ColumnGroup` and its child

Open Jolanrensen opened this issue 2 years ago • 2 comments

Similar to https://github.com/Kotlin/dataframe/issues/405, also replace breaks when running on both a ColumnGroup and its child.

Current implementation:

public fun <T, C> ReplaceClause<T, C>.with(transform: ColumnsContainer<T>.(DataColumn<C>) -> AnyBaseCol): DataFrame<T> {
    val removeResult = df.removeImpl(columns = columns)
    // removeResult.removedColumns contains the removed columns, but only the roots, so `group.child` is not 
    // included, just `group`, meaning `transform` will not be called on `child`
    val toInsert = removeResult.removedColumns.map {
        val newCol = transform(df, it.data.column as DataColumn<C>)
        
        // pathFromRoot() returns the original path with a name change
        // will be incorrect if one of its parents had a rename
        ColumnToInsert(it.pathFromRoot().dropLast(1) + newCol.name, newCol, it)
    }
    return removeResult.df.insertImpl(toInsert)
}

Jolanrensen avatar Jun 27 '23 19:06 Jolanrensen

Also need to look into move for similar behavior.

Jolanrensen avatar Jun 27 '23 19:06 Jolanrensen

could also provide a warning in the meantime

Jolanrensen avatar Jun 28 '23 10:06 Jolanrensen