Skip to content

Commit

Permalink
Merge pull request #920 from Kotlin/flatten-separator
Browse files Browse the repository at this point in the history
Change default flatten parent-child separator to "_"
  • Loading branch information
Jolanrensen authored Oct 16, 2024
2 parents 117e958 + fbcb8ff commit ddfb7b9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,33 @@ import kotlin.reflect.KProperty

@Refine
@Interpretable("FlattenDefault")
public fun <T> DataFrame<T>.flatten(keepParentNameForColumns: Boolean = false, separator: String = "."): DataFrame<T> =
public fun <T> DataFrame<T>.flatten(keepParentNameForColumns: Boolean = false, separator: String = "_"): DataFrame<T> =
flatten(keepParentNameForColumns, separator) { all() }

@Refine
@Interpretable("Flatten0")
public fun <T, C> DataFrame<T>.flatten(
keepParentNameForColumns: Boolean = false,
separator: String = ".",
separator: String = "_",
columns: ColumnsSelector<T, C>,
): DataFrame<T> = flattenImpl(columns, keepParentNameForColumns, separator)

public fun <T> DataFrame<T>.flatten(
vararg columns: String,
keepParentNameForColumns: Boolean = false,
separator: String = ".",
separator: String = "_",
): DataFrame<T> = flatten(keepParentNameForColumns, separator) { columns.toColumnSet() }

public fun <T, C> DataFrame<T>.flatten(
vararg columns: ColumnReference<C>,
keepParentNameForColumns: Boolean = false,
separator: String = ".",
separator: String = "_",
): DataFrame<T> = flatten(keepParentNameForColumns, separator) { columns.toColumnSet() }

public fun <T, C> DataFrame<T>.flatten(
vararg columns: KProperty<C>,
keepParentNameForColumns: Boolean = false,
separator: String = ".",
separator: String = "_",
): DataFrame<T> = flatten(keepParentNameForColumns, separator) { columns.toColumnSet() }

// endregion
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.jetbrains.kotlinx.dataframe.impl.columns.toColumnSet
internal fun <T, C> DataFrame<T>.flattenImpl(
columns: ColumnsSelector<T, C>,
keepParentNameForColumns: Boolean = false,
separator: String = ".",
separator: String = "_",
): DataFrame<T> {
val rootColumns = getColumnsWithPaths {
columns.toColumnSet().filter { it.isColumnGroup() }.simplify()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class FlattenTests {

aggregate
.flatten(keepParentNameForColumns = true)
.columnNames() shouldBe listOf("city", "mean.age", "mean.weight", "std.age", "std.weight")
.columnNames() shouldBe listOf("city", "mean_age", "mean_weight", "std_age", "std_weight")

aggregate
.flatten(keepParentNameForColumns = true, separator = "_happy_separator_")
Expand Down

0 comments on commit ddfb7b9

Please sign in to comment.