Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -4502,6 +4502,7 @@ public final class org/jetbrains/kotlinx/dataframe/api/TypeConversionsKt {
public static final fun toColumnOf (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnPath;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnAccessor;
public static final fun toDataFrame (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Lorg/jetbrains/kotlinx/dataframe/DataFrame;
public static final fun toDataFrame (Lorg/jetbrains/kotlinx/dataframe/columns/BaseColumn;)Lorg/jetbrains/kotlinx/dataframe/DataFrame;
public static final fun toDataRow (Ljava/util/Map;)Lorg/jetbrains/kotlinx/dataframe/DataRow;
public static final fun toDoubleArray (Lorg/jetbrains/kotlinx/dataframe/DataColumn;)[D
public static final fun toFloatArray (Lorg/jetbrains/kotlinx/dataframe/DataColumn;)[F
public static final fun toFrameColumn (Ljava/lang/Iterable;Ljava/lang/String;)Lorg/jetbrains/kotlinx/dataframe/columns/FrameColumn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private fun Any?.toDataFrameLikeOrNull(): DataFrameLike? =
when (this) {
is AnyFrame -> {
object : DataFrameLike {
override fun configuration(default: DisplayConfiguration) = default
override fun configuration(default: DisplayConfiguration) = default.copy(cellFormatter = null)

override fun df(): AnyFrame = this@toDataFrameLikeOrNull
}
Expand Down
28 changes: 28 additions & 0 deletions core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/format.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.kotest.matchers.shouldNotBe
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl.blue
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl.red
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl.rgb
import org.jetbrains.kotlinx.dataframe.io.DataFrameHtmlData
import org.jetbrains.kotlinx.dataframe.io.DisplayConfiguration
import org.jetbrains.kotlinx.dataframe.samples.api.TestBase
import org.jetbrains.kotlinx.dataframe.samples.api.age
Expand Down Expand Up @@ -312,4 +313,31 @@ class FormatTests : TestBase() {
html.split("background-color:#00ff00").size - 1 shouldBe 5 // Only non-null weight values get formatted
formatted::class.simpleName shouldBe "FormattedFrame"
}

// Issue #982
@Suppress("ktlint:standard:argument-list-wrapping")
@Test
fun `formatting a column shouldn't affect nested columns with the same name`() {
val df = dataFrameOf("firstName", "lastName", "age", "city", "weight", "isHappy")(
"Alice", "Cooper", 15, "London", 54, true,
"Bob", "Dylan", 45, "Dubai", 87, true,
"Charlie", "Daniels", 20, "Moscow", null, false,
"Charlie", "Chaplin", 40, "Milan", null, true,
"Bob", "Marley", 30, "Tokyo", 68, true,
"Alice", "Wolf", 20, null, 55, false,
"Charlie", "Byrd", 30, "Moscow", 90, true,
).group("firstName", "lastName").into("name")
.groupBy("city").toDataFrame()
.add("cityCopy") { "city"<String>() }
.group("city").into("cityGroup")
.rename("cityCopy").into("city")

val formatted = df.format("city").with { bold and italic and textColor(green) }
val html =
formatted.toStandaloneHtml() + // expand the nested dataframes so we can see the difference
DataFrameHtmlData(script = "document.querySelectorAll('a.expander').forEach(a => a.click());")

html.toString().split("color:#00ff00").size - 1 shouldBe 12
html.toString().split("font-style:italic").size - 1 shouldBe 6
}
}