@@ -6,29 +6,8 @@ import org.jetbrains.kotlinx.dataframe.AnyCol
6
6
import org.jetbrains.kotlinx.dataframe.AnyFrame
7
7
import org.jetbrains.kotlinx.dataframe.AnyRow
8
8
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
9
- import org.jetbrains.kotlinx.dataframe.api.Convert
10
- import org.jetbrains.kotlinx.dataframe.api.FormattedFrame
11
- import org.jetbrains.kotlinx.dataframe.api.Gather
12
- import org.jetbrains.kotlinx.dataframe.api.GroupBy
13
- import org.jetbrains.kotlinx.dataframe.api.Merge
14
- import org.jetbrains.kotlinx.dataframe.api.Pivot
15
- import org.jetbrains.kotlinx.dataframe.api.PivotGroupBy
16
- import org.jetbrains.kotlinx.dataframe.api.ReducedGroupBy
17
- import org.jetbrains.kotlinx.dataframe.api.ReducedPivot
18
- import org.jetbrains.kotlinx.dataframe.api.ReducedPivotGroupBy
19
- import org.jetbrains.kotlinx.dataframe.api.Split
20
- import org.jetbrains.kotlinx.dataframe.api.SplitWithTransform
21
- import org.jetbrains.kotlinx.dataframe.api.Update
22
- import org.jetbrains.kotlinx.dataframe.api.asColumnGroup
23
- import org.jetbrains.kotlinx.dataframe.api.asDataFrame
24
- import org.jetbrains.kotlinx.dataframe.api.columnsCount
25
- import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
26
- import org.jetbrains.kotlinx.dataframe.api.frames
27
- import org.jetbrains.kotlinx.dataframe.api.into
28
- import org.jetbrains.kotlinx.dataframe.api.isColumnGroup
9
+ import org.jetbrains.kotlinx.dataframe.api.*
29
10
import org.jetbrains.kotlinx.dataframe.api.name
30
- import org.jetbrains.kotlinx.dataframe.api.toDataFrame
31
- import org.jetbrains.kotlinx.dataframe.api.values
32
11
import org.jetbrains.kotlinx.dataframe.codeGen.CodeWithConverter
33
12
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
34
13
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
@@ -111,42 +90,42 @@ internal class Integration(
111
90
}
112
91
113
92
with (JupyterHtmlRenderer (config.display, this )) {
93
+ render<DisableRowsLimitWrapper >(
94
+ { " DataRow: index = ${it.value.rowsCount()} , columnsCount = ${it.value.columnsCount()} " },
95
+ applyRowsLimit = false
96
+ )
97
+
114
98
render<HtmlData > { notebook.renderHtmlAsIFrameIfNeeded(it) }
115
99
render<AnyRow >(
116
- { it.toDataFrame() },
117
100
{ " DataRow: index = ${it.index()} , columnsCount = ${it.columnsCount()} " },
118
101
)
119
102
render<ColumnGroup <* >>(
120
- { it.asDataFrame() },
121
103
{ """ ColumnGroup: name = "${it.name} ", rowsCount = ${it.rowsCount()} , columnsCount = ${it.columnsCount()} """ },
122
104
)
123
105
render<AnyCol >(
124
- { dataFrameOf(it) },
125
106
{ """ DataColumn: name = "${it.name} ", type = ${renderType(it.type())} , size = ${it.size()} """ },
126
107
)
127
108
render<AnyFrame >(
128
- { it },
129
- { " DataFrame: rowsCount = ${it.rowsCount()} , columnsCount = ${it.columnsCount()} " },
109
+ { " DataFrame: rowsCount = ${it.rowsCount()} , columnsCount = ${it.columnsCount()} " }
130
110
)
131
111
render<FormattedFrame <* >>(
132
- { it.df },
133
112
{ " DataFrame: rowsCount = ${it.df.rowsCount()} , columnsCount = ${it.df.columnsCount()} " },
134
113
modifyConfig = { getDisplayConfiguration(it) },
135
114
)
136
- render<GroupBy <* , * >>({ it.toDataFrame() }, { " GroupBy" })
137
- render<ReducedGroupBy <* , * >>({ it.into(it.groupBy.groups.name()) }, { " ReducedGroupBy" })
138
- render<Pivot <* >>({ it.frames().toDataFrame() }, { " Pivot" })
139
- render<ReducedPivot <* >>({ it.values().toDataFrame() }, { " ReducedPivot" })
140
- render<PivotGroupBy <* >>({ it.frames() }, { " PivotGroupBy" })
141
- render<ReducedPivotGroupBy <* >>({ it.values() }, { " ReducedPivotGroupBy" })
142
- render<SplitWithTransform <* , * , * >>({ it.into() }, { " Split" })
143
- render<Split <* , * >>({ it.toDataFrame() }, { " Split" })
144
- render<Merge <* , * , * >>({ it.into( " merged " ) }, { " Merge" })
145
- render<Gather <* , * , * , * >>({ it.into( " key " , " value " ) }, { " Gather" })
115
+ render<GroupBy <* , * >>({ " GroupBy" })
116
+ render<ReducedGroupBy <* , * >>({ " ReducedGroupBy" })
117
+ render<Pivot <* >>({ " Pivot" })
118
+ render<ReducedPivot <* >>({ " ReducedPivot" })
119
+ render<PivotGroupBy <* >>({ " PivotGroupBy" })
120
+ render<ReducedPivotGroupBy <* >>({ " ReducedPivotGroupBy" })
121
+ render<SplitWithTransform <* , * , * >>({ " Split" })
122
+ render<Split <* , * >>({ " Split" })
123
+ render<Merge <* , * , * >>({ " Merge" })
124
+ render<Gather <* , * , * , * >>({ " Gather" })
146
125
render<IMG > { HTML (it.toString()) }
147
126
render<IFRAME > { HTML (it.toString()) }
148
- render<Update <* , * >>({ it.df }, { " Update" })
149
- render<Convert <* , * >>({ it.df }, { " Convert" })
127
+ render<Update <* , * >>({ " Update" })
128
+ render<Convert <* , * >>({ " Convert" })
150
129
}
151
130
152
131
import(" org.jetbrains.kotlinx.dataframe.api.*" )
@@ -156,6 +135,7 @@ internal class Integration(
156
135
import(" org.jetbrains.kotlinx.dataframe.columns.*" )
157
136
import(" org.jetbrains.kotlinx.dataframe.jupyter.ImportDataSchema" )
158
137
import(" org.jetbrains.kotlinx.dataframe.jupyter.importDataSchema" )
138
+ import(" org.jetbrains.kotlinx.dataframe.jupyter.KotlinNotebookPluginUtils" )
159
139
import(" java.net.URL" )
160
140
import(" java.io.File" )
161
141
import(" kotlinx.datetime.Instant" )
@@ -265,3 +245,28 @@ public fun KotlinKernelHost.useSchemas(schemaClasses: Iterable<KClass<*>>) {
265
245
public fun KotlinKernelHost.useSchemas (vararg schemaClasses : KClass <* >): Unit = useSchemas(schemaClasses.asIterable())
266
246
267
247
public inline fun <reified T > KotlinKernelHost.useSchema (): Unit = useSchemas(T ::class )
248
+
249
+ /* *
250
+ * Converts [dataframeLike] to [AnyFrame].
251
+ * If [dataframeLike] is already [AnyFrame] then it is returned as is.
252
+ * If it's not possible to convert [dataframeLike] to [AnyFrame] then [IllegalArgumentException] is thrown.
253
+ */
254
+ internal fun convertToDataFrame (dataframeLike : Any ): AnyFrame =
255
+ when (dataframeLike) {
256
+ is Pivot <* > -> dataframeLike.frames().toDataFrame()
257
+ is ReducedPivot <* > -> dataframeLike.values().toDataFrame()
258
+ is PivotGroupBy <* > -> dataframeLike.frames()
259
+ is ReducedPivotGroupBy <* > -> dataframeLike.values()
260
+ is SplitWithTransform <* , * , * > -> dataframeLike.into()
261
+ is Merge <* , * , * > -> dataframeLike.into(" merged" )
262
+ is Gather <* , * , * , * > -> dataframeLike.into(" key" , " value" )
263
+ is Update <* , * > -> dataframeLike.df
264
+ is Convert <* , * > -> dataframeLike.df
265
+ is FormattedFrame <* > -> dataframeLike.df
266
+ is AnyCol -> dataFrameOf(dataframeLike)
267
+ is AnyRow -> dataframeLike.toDataFrame()
268
+ is GroupBy <* , * > -> dataframeLike.toDataFrame()
269
+ is AnyFrame -> dataframeLike
270
+ is DisableRowsLimitWrapper -> dataframeLike.value
271
+ else -> throw IllegalArgumentException (" Unsupported type: ${dataframeLike::class } " )
272
+ }
0 commit comments