dataframe icon indicating copy to clipboard operation
dataframe copied to clipboard

HTML formatting for a column affects other columns with same name

Open Jolanrensen opened this issue 1 year ago • 1 comments

Given the following example

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")

// affects city, cityGroup.city, and group[*].city
df.format("city").with {
    bold and italic and textColor(green)
}.toStandaloneHTML().openInBrowser()

We'd expect only city to be affected by the format operation, but cityGroup.city and all city columns inside group are also affected.

image

Jolanrensen avatar Dec 03 '24 15:12 Jolanrensen

image

It also seems that frame columns and column groups are excluded? I'd expect the group column to get black backgrounds as well in this example. (https://github.com/Kotlin/dataframe/issues/1356)

Jolanrensen avatar Dec 03 '24 15:12 Jolanrensen

I will revisit the format implementation later.

We will need to make a recommended way to format nested dataframes https://github.com/Kotlin/dataframe/issues/1375

Jolanrensen avatar Jul 29 '25 11:07 Jolanrensen

Actually, currently the example is even more broken than it was before...

cityGroup:
    city: String?
group: *
    name:
        firstName: String
        lastName: String
    age: Int
    city: String?
    weight: Int?
    isHappy: Boolean
city: String?

this is when it's querying for name.firstName. It tries to fetch its parent from the outer dataframe, instead of the nested one...

Column not found: '[name]'
java.lang.IllegalArgumentException: Column not found: '[name]'
	at org.jetbrains.kotlinx.dataframe.api.DataFrameGetKt.getColumn(DataFrameGet.kt:107)
	at org.jetbrains.kotlinx.dataframe.ColumnsContainer.get(ColumnsContainer.kt:65)
	at org.jetbrains.kotlinx.dataframe.io.HtmlKt.toHtmlData$columnToJs(html.kt:206)
	at org.jetbrains.kotlinx.dataframe.io.HtmlKt.toHtmlData$columnToJs(html.kt:239)
	at org.jetbrains.kotlinx.dataframe.io.HtmlKt.toHtmlData(html.kt:258)
	at org.jetbrains.kotlinx.dataframe.io.HtmlKt.toHtml(html.kt:668)
	at org.jetbrains.kotlinx.dataframe.io.HtmlKt.toStandaloneHtml(html.kt:626)
	at org.jetbrains.kotlinx.dataframe.io.HtmlKt.toStandaloneHtml$default(html.kt:622)
	at org.jetbrains.kotlinx.dataframe.api.FormattedFrame.toStandaloneHtml(format.kt:824)
	at org.jetbrains.kotlinx.dataframe.api.FormattedFrame.toStandaloneHtml$default(format.kt:823)

Nested dataframes definitely need to be treated independently

Jolanrensen avatar Sep 11 '25 18:09 Jolanrensen