Skip to content

Commit bfc4a25

Browse files
Automated commit of generated code
1 parent c043b2d commit bfc4a25

File tree

5 files changed

+226
-78
lines changed

5 files changed

+226
-78
lines changed

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/format.kt

Lines changed: 116 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.jetbrains.kotlinx.dataframe.api
22

33
import org.jetbrains.kotlinx.dataframe.ColumnsSelector
4-
import org.jetbrains.kotlinx.dataframe.DataColumn
54
import org.jetbrains.kotlinx.dataframe.DataFrame
65
import org.jetbrains.kotlinx.dataframe.DataRow
76
import org.jetbrains.kotlinx.dataframe.RowColumnExpression
@@ -15,7 +14,10 @@ import org.jetbrains.kotlinx.dataframe.api.FormattingDsl.linear
1514
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl.linearBg
1615
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl.rgb
1716
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl.textColor
17+
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
1818
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
19+
import org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath
20+
import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
1921
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
2022
import org.jetbrains.kotlinx.dataframe.dataTypes.IFRAME
2123
import org.jetbrains.kotlinx.dataframe.dataTypes.IMG
@@ -59,6 +61,21 @@ import kotlin.reflect.KProperty
5961
*
6062
* You can continue formatting the [FormattedFrame] by calling [format][FormattedFrame.format] on it again.
6163
*
64+
* Specifying a [column group][ColumnGroup] makes all of its inner columns be formatted in the same way unless
65+
* overridden.
66+
*
67+
* Formatting is done additively, meaning you can add more formatting to a cell that's already formatted or
68+
* override certain attributes inherited from its outer group.
69+
*
70+
* Specifying a [frame column][FrameColumn] at the moment does nothing
71+
* ([Issue #1375](https://github.com/Kotlin/dataframe/issues/1375)),
72+
* convert each nested [DataFrame] to a [FormattedFrame] instead:
73+
* ```kt
74+
* df.convert { myFrameCol }.with {
75+
* it.format { someCol }.with { background(green) }
76+
* }.toStandaloneHtml()
77+
* ```
78+
*
6279
* Check out the [Grammar].
6380
*
6481
* For more information: [See `format` on the documentation website.](https://kotlin.github.io/dataframe/format.html)
@@ -148,7 +165,7 @@ internal interface FormatDocs {
148165
*
149166
*     
150167
*
151-
* `rowColFormatter: `[FormattingDsl][org.jetbrains.kotlinx.dataframe.api.FormatDocs.Grammar.FormattingDslGrammarDef]`.(row: `[DataRow][org.jetbrains.kotlinx.dataframe.DataRow]`<T>, col: `[DataColumn][org.jetbrains.kotlinx.dataframe.DataColumn]`<C>) -> `[CellAttributes][org.jetbrains.kotlinx.dataframe.api.CellAttributes]`?`
168+
* `rowColFormatter: `[FormattingDsl][org.jetbrains.kotlinx.dataframe.api.FormatDocs.Grammar.FormattingDslGrammarDef]`.(row: `[DataRow][org.jetbrains.kotlinx.dataframe.DataRow]`<T>, col: `[ColumnWithPath][org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath]`<C>) -> `[CellAttributes][org.jetbrains.kotlinx.dataframe.api.CellAttributes]`?`
152169
*
153170
* ### Notation:
154171
*
@@ -262,7 +279,7 @@ internal interface FormatDocs {
262279
interface CellFormatterDef
263280

264281
/**
265-
* `rowColFormatter: `[FormattingDsl][org.jetbrains.kotlinx.dataframe.api.FormatDocs.Grammar.FormattingDslGrammarDef]`.(row: `[DataRow][DataRow]`<T>, col: `[DataColumn][DataColumn]`<C>) -> `[CellAttributes][CellAttributes]`?`
282+
* `rowColFormatter: `[FormattingDsl][org.jetbrains.kotlinx.dataframe.api.FormatDocs.Grammar.FormattingDslGrammarDef]`.(row: `[DataRow][DataRow]`<T>, col: `[ColumnWithPath][ColumnWithPath]`<C>) -> `[CellAttributes][CellAttributes]`?`
266283
*/
267284
interface RowColFormatterDef
268285

@@ -300,6 +317,21 @@ internal interface FormatDocs {
300317
*
301318
* You can continue formatting the [FormattedFrame][org.jetbrains.kotlinx.dataframe.api.FormattedFrame] by calling [format][org.jetbrains.kotlinx.dataframe.api.FormattedFrame.format] on it again.
302319
*
320+
* Specifying a [column group][org.jetbrains.kotlinx.dataframe.columns.ColumnGroup] makes all of its inner columns be formatted in the same way unless
321+
* overridden.
322+
*
323+
* Formatting is done additively, meaning you can add more formatting to a cell that's already formatted or
324+
* override certain attributes inherited from its outer group.
325+
*
326+
* Specifying a [frame column][org.jetbrains.kotlinx.dataframe.columns.FrameColumn] at the moment does nothing
327+
* ([Issue #1375](https://github.com/Kotlin/dataframe/issues/1375)),
328+
* convert each nested [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to a [FormattedFrame][org.jetbrains.kotlinx.dataframe.api.FormattedFrame] instead:
329+
* ```kt
330+
* df.convert { myFrameCol }.with {
331+
* it.format { someCol }.with { background(green) }
332+
* }.toStandaloneHtml()
333+
* ```
334+
*
303335
* Check out the [Grammar][org.jetbrains.kotlinx.dataframe.api.FormatDocs.Grammar].
304336
*
305337
* For more information: [See `format` on the documentation website.](https://kotlin.github.io/dataframe/format.html)
@@ -357,6 +389,21 @@ public fun <T, C> DataFrame<T>.format(columns: ColumnsSelector<T, C>): FormatCla
357389
*
358390
* You can continue formatting the [FormattedFrame][org.jetbrains.kotlinx.dataframe.api.FormattedFrame] by calling [format][org.jetbrains.kotlinx.dataframe.api.FormattedFrame.format] on it again.
359391
*
392+
* Specifying a [column group][org.jetbrains.kotlinx.dataframe.columns.ColumnGroup] makes all of its inner columns be formatted in the same way unless
393+
* overridden.
394+
*
395+
* Formatting is done additively, meaning you can add more formatting to a cell that's already formatted or
396+
* override certain attributes inherited from its outer group.
397+
*
398+
* Specifying a [frame column][org.jetbrains.kotlinx.dataframe.columns.FrameColumn] at the moment does nothing
399+
* ([Issue #1375](https://github.com/Kotlin/dataframe/issues/1375)),
400+
* convert each nested [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to a [FormattedFrame][org.jetbrains.kotlinx.dataframe.api.FormattedFrame] instead:
401+
* ```kt
402+
* df.convert { myFrameCol }.with {
403+
* it.format { someCol }.with { background(green) }
404+
* }.toStandaloneHtml()
405+
* ```
406+
*
360407
* Check out the [Grammar][org.jetbrains.kotlinx.dataframe.api.FormatDocs.Grammar].
361408
*
362409
* For more information: [See `format` on the documentation website.](https://kotlin.github.io/dataframe/format.html)
@@ -397,6 +444,21 @@ public fun <T> DataFrame<T>.format(vararg columns: String): FormatClause<T, Any?
397444
*
398445
* You can continue formatting the [FormattedFrame][org.jetbrains.kotlinx.dataframe.api.FormattedFrame] by calling [format][org.jetbrains.kotlinx.dataframe.api.FormattedFrame.format] on it again.
399446
*
447+
* Specifying a [column group][org.jetbrains.kotlinx.dataframe.columns.ColumnGroup] makes all of its inner columns be formatted in the same way unless
448+
* overridden.
449+
*
450+
* Formatting is done additively, meaning you can add more formatting to a cell that's already formatted or
451+
* override certain attributes inherited from its outer group.
452+
*
453+
* Specifying a [frame column][org.jetbrains.kotlinx.dataframe.columns.FrameColumn] at the moment does nothing
454+
* ([Issue #1375](https://github.com/Kotlin/dataframe/issues/1375)),
455+
* convert each nested [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to a [FormattedFrame][org.jetbrains.kotlinx.dataframe.api.FormattedFrame] instead:
456+
* ```kt
457+
* df.convert { myFrameCol }.with {
458+
* it.format { someCol }.with { background(green) }
459+
* }.toStandaloneHtml()
460+
* ```
461+
*
400462
* Check out the [Grammar][org.jetbrains.kotlinx.dataframe.api.FormatDocs.Grammar].
401463
*
402464
* For more information: [See `format` on the documentation website.](https://kotlin.github.io/dataframe/format.html)
@@ -450,6 +512,21 @@ public fun <T, C> DataFrame<T>.format(vararg columns: KProperty<C>): FormatClaus
450512
*
451513
* You can continue formatting the [FormattedFrame][org.jetbrains.kotlinx.dataframe.api.FormattedFrame] by calling [format][org.jetbrains.kotlinx.dataframe.api.FormattedFrame.format] on it again.
452514
*
515+
* Specifying a [column group][org.jetbrains.kotlinx.dataframe.columns.ColumnGroup] makes all of its inner columns be formatted in the same way unless
516+
* overridden.
517+
*
518+
* Formatting is done additively, meaning you can add more formatting to a cell that's already formatted or
519+
* override certain attributes inherited from its outer group.
520+
*
521+
* Specifying a [frame column][org.jetbrains.kotlinx.dataframe.columns.FrameColumn] at the moment does nothing
522+
* ([Issue #1375](https://github.com/Kotlin/dataframe/issues/1375)),
523+
* convert each nested [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to a [FormattedFrame][org.jetbrains.kotlinx.dataframe.api.FormattedFrame] instead:
524+
* ```kt
525+
* df.convert { myFrameCol }.with {
526+
* it.format { someCol }.with { background(green) }
527+
* }.toStandaloneHtml()
528+
* ```
529+
*
453530
* Check out the [Grammar][org.jetbrains.kotlinx.dataframe.api.FormatDocs.Grammar].
454531
*
455532
* For more information: [See `format` on the documentation website.](https://kotlin.github.io/dataframe/format.html)
@@ -509,6 +586,21 @@ public fun <T, C> FormattedFrame<T>.format(columns: ColumnsSelector<T, C>): Form
509586
*
510587
* You can continue formatting the [FormattedFrame][org.jetbrains.kotlinx.dataframe.api.FormattedFrame] by calling [format][org.jetbrains.kotlinx.dataframe.api.FormattedFrame.format] on it again.
511588
*
589+
* Specifying a [column group][org.jetbrains.kotlinx.dataframe.columns.ColumnGroup] makes all of its inner columns be formatted in the same way unless
590+
* overridden.
591+
*
592+
* Formatting is done additively, meaning you can add more formatting to a cell that's already formatted or
593+
* override certain attributes inherited from its outer group.
594+
*
595+
* Specifying a [frame column][org.jetbrains.kotlinx.dataframe.columns.FrameColumn] at the moment does nothing
596+
* ([Issue #1375](https://github.com/Kotlin/dataframe/issues/1375)),
597+
* convert each nested [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to a [FormattedFrame][org.jetbrains.kotlinx.dataframe.api.FormattedFrame] instead:
598+
* ```kt
599+
* df.convert { myFrameCol }.with {
600+
* it.format { someCol }.with { background(green) }
601+
* }.toStandaloneHtml()
602+
* ```
603+
*
512604
* Check out the [Grammar][org.jetbrains.kotlinx.dataframe.api.FormatDocs.Grammar].
513605
*
514606
* For more information: [See `format` on the documentation website.](https://kotlin.github.io/dataframe/format.html)
@@ -550,6 +642,21 @@ public fun <T> FormattedFrame<T>.format(vararg columns: String): FormatClause<T,
550642
*
551643
* You can continue formatting the [FormattedFrame][org.jetbrains.kotlinx.dataframe.api.FormattedFrame] by calling [format][org.jetbrains.kotlinx.dataframe.api.FormattedFrame.format] on it again.
552644
*
645+
* Specifying a [column group][org.jetbrains.kotlinx.dataframe.columns.ColumnGroup] makes all of its inner columns be formatted in the same way unless
646+
* overridden.
647+
*
648+
* Formatting is done additively, meaning you can add more formatting to a cell that's already formatted or
649+
* override certain attributes inherited from its outer group.
650+
*
651+
* Specifying a [frame column][org.jetbrains.kotlinx.dataframe.columns.FrameColumn] at the moment does nothing
652+
* ([Issue #1375](https://github.com/Kotlin/dataframe/issues/1375)),
653+
* convert each nested [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to a [FormattedFrame][org.jetbrains.kotlinx.dataframe.api.FormattedFrame] instead:
654+
* ```kt
655+
* df.convert { myFrameCol }.with {
656+
* it.format { someCol }.with { background(green) }
657+
* }.toStandaloneHtml()
658+
* ```
659+
*
553660
* Check out the [Grammar][org.jetbrains.kotlinx.dataframe.api.FormatDocs.Grammar].
554661
*
555662
* For more information: [See `format` on the documentation website.](https://kotlin.github.io/dataframe/format.html)
@@ -570,7 +677,7 @@ public fun <T> FormattedFrame<T>.format(vararg columns: String): FormatClause<T,
570677
* .toStandaloneHtml().openInBrowser()
571678
* ```
572679
*/
573-
public fun <T> FormattedFrame<T>.format(): FormatClause<T, Any?> = FormatClause(df, null, formatter)
680+
public fun <T> FormattedFrame<T>.format(): FormatClause<T, Any?> = FormatClause(df = df, oldFormatter = formatter)
574681

575682
// endregion
576683

@@ -665,7 +772,7 @@ public fun <T, C> FormatClause<T, C?>.notNull(): FormatClause<T, C> = where { it
665772
* Creates a new [FormattedFrame] that uses the specified [RowColFormatter] to format the selected cells of the dataframe.
666773
*
667774
* You need to specify [formatter]: A lambda function expecting a [CellAttributes][org.jetbrains.kotlinx.dataframe.api.CellAttributes] or `null` given an instance of
668-
* [DataRow][org.jetbrains.kotlinx.dataframe.DataRow]`<`[T][T]`>` and [DataColumn][org.jetbrains.kotlinx.dataframe.DataColumn]`<`[C][C]`>`.
775+
* [DataRow][org.jetbrains.kotlinx.dataframe.DataRow]`<`[T][T]`>` and [ColumnWithPath][org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath]`<`[C][C]`>`.
669776
*
670777
* This is similar to a [RowColumnExpression][org.jetbrains.kotlinx.dataframe.RowColumnExpression], except that you also have access
671778
* to the [FormattingDsl][org.jetbrains.kotlinx.dataframe.api.FormattingDsl] in the context.
@@ -730,7 +837,7 @@ public fun <T, C> FormatClause<T, C>.perRowCol(formatter: RowColFormatter<T, C>)
730837
*/
731838
@Suppress("UNCHECKED_CAST")
732839
public fun <T, C> FormatClause<T, C>.with(formatter: CellFormatter<C>): FormattedFrame<T> =
733-
formatImpl { row, col -> formatter(row[col.name] as C) }
840+
formatImpl { row, col -> formatter(col[row] as C) }
734841

735842
/**
736843
* Creates a new [FormattedFrame] that uses the specified [CellFormatter] to format selected non-null cells of the dataframe.
@@ -1011,7 +1118,7 @@ public object FormattingDsl {
10111118

10121119
/**
10131120
* A lambda function expecting a [CellAttributes] or `null` given an instance of
1014-
* [DataRow][DataRow]`<`[T][T]`>` and [DataColumn][DataColumn]`<`[C][C]`>`.
1121+
* [DataRow][DataRow]`<`[T][T]`>` and [ColumnWithPath][ColumnWithPath]`<`[C][C]`>`.
10151122
*
10161123
* This is similar to a [RowColumnExpression], except that you also have access
10171124
* to the [FormattingDsl] in the context.
@@ -1031,7 +1138,7 @@ public object FormattingDsl {
10311138
*
10321139
* Use [attr][org.jetbrains.kotlinx.dataframe.api.FormattingDsl.attr] if you want to specify a custom CSS attribute.
10331140
*/
1034-
public typealias RowColFormatter<T, C> = FormattingDsl.(row: DataRow<T>, col: DataColumn<C>) -> CellAttributes?
1141+
public typealias RowColFormatter<T, C> = FormattingDsl.(row: DataRow<T>, col: ColumnWithPath<C>) -> CellAttributes?
10351142

10361143
/**
10371144
* A lambda function expecting a [CellAttributes] or `null` given an instance of a cell: [C] of the dataframe.
@@ -1141,7 +1248,7 @@ public class FormattedFrame<T>(internal val df: DataFrame<T>, internal val forma
11411248
*/
11421249
public class FormatClause<T, C>(
11431250
internal val df: DataFrame<T>,
1144-
internal val columns: ColumnsSelector<T, C>? = null,
1251+
internal val columns: ColumnsSelector<T, C> = { all().cast() },
11451252
internal val oldFormatter: RowColFormatter<T, C>? = null,
11461253
internal val filter: RowValueFilter<T, C> = { true },
11471254
) {

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/format.kt

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import org.jetbrains.kotlinx.dataframe.api.RgbColor
88
import org.jetbrains.kotlinx.dataframe.api.RowColFormatter
99
import org.jetbrains.kotlinx.dataframe.api.and
1010
import org.jetbrains.kotlinx.dataframe.api.cast
11-
import org.jetbrains.kotlinx.dataframe.api.getColumnsWithPaths
12-
import org.jetbrains.kotlinx.dataframe.api.name
13-
import org.jetbrains.kotlinx.dataframe.columns.depth
11+
import org.jetbrains.kotlinx.dataframe.api.getColumnPaths
12+
import org.jetbrains.kotlinx.dataframe.columns.UnresolvedColumnsPolicy
13+
import org.jetbrains.kotlinx.dataframe.impl.getColumnPaths
14+
import org.jetbrains.kotlinx.dataframe.path
1415

1516
internal class SingleAttribute(val key: String, val value: String) : CellAttributes {
1617
override fun attributes() = listOf(key to value)
@@ -53,25 +54,17 @@ internal inline fun <T, C> FormatClause<T, C>.formatImpl(
5354
crossinline formatter: RowColFormatter<T, C>,
5455
): FormattedFrame<T> {
5556
val clause = this
56-
val columns =
57-
if (clause.columns != null) {
58-
clause.df.getColumnsWithPaths(clause.columns)
59-
.mapNotNull { if (it.depth == 0) it.name else null } // TODO Causes #1356
60-
.toSet()
61-
} else {
62-
null
63-
}
57+
val columns = clause.df.getColumnPaths(UnresolvedColumnsPolicy.Skip, clause.columns).toSet()
58+
6459
return FormattedFrame(clause.df) { row, col ->
6560
val oldAttributes = clause.oldFormatter?.invoke(FormattingDsl, row, col.cast())
66-
if (columns == null || columns.contains(col.name())) {
67-
val value = row[col.name] as C
61+
if (col.path in columns) {
62+
val value = col[row] as C
6863
if (clause.filter(row, value)) {
69-
oldAttributes and formatter(FormattingDsl, row.cast(), col.cast())
70-
} else {
71-
oldAttributes
64+
return@FormattedFrame oldAttributes and formatter(FormattingDsl, row.cast(), col.cast())
7265
}
73-
} else {
74-
oldAttributes
7566
}
67+
68+
oldAttributes
7669
}
7770
}

0 commit comments

Comments
 (0)