Skip to content

Commit be83d45

Browse files
committed
Extract functions used by IDEA plugin to utility class
1 parent 15ca36d commit be83d45

File tree

2 files changed

+37
-22
lines changed

2 files changed

+37
-22
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/Integration.kt

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ internal class Integration(
135135
import("org.jetbrains.kotlinx.dataframe.columns.*")
136136
import("org.jetbrains.kotlinx.dataframe.jupyter.ImportDataSchema")
137137
import("org.jetbrains.kotlinx.dataframe.jupyter.importDataSchema")
138-
import("org.jetbrains.kotlinx.dataframe.jupyter.getRowsSubsetForRendering")
138+
import("org.jetbrains.kotlinx.dataframe.jupyter.KotlinNotebookPluginUtils")
139139
import("java.net.URL")
140140
import("java.io.File")
141141
import("kotlinx.datetime.Instant")
@@ -251,7 +251,7 @@ public inline fun <reified T> KotlinKernelHost.useSchema(): Unit = useSchemas(T:
251251
* If [dataframeLike] is already [AnyFrame] then it is returned as is.
252252
* If it's not possible to convert [dataframeLike] to [AnyFrame] then [IllegalArgumentException] is thrown.
253253
*/
254-
public fun convertToDataFrame(dataframeLike: Any): AnyFrame =
254+
internal fun convertToDataFrame(dataframeLike: Any): AnyFrame =
255255
when (dataframeLike) {
256256
is Pivot<*> -> dataframeLike.frames().toDataFrame()
257257
is ReducedPivot<*> -> dataframeLike.values().toDataFrame()
@@ -270,23 +270,3 @@ public fun convertToDataFrame(dataframeLike: Any): AnyFrame =
270270
is DisableRowsLimitWrapper -> dataframeLike.value
271271
else -> throw IllegalArgumentException("Unsupported type: ${dataframeLike::class}")
272272
}
273-
274-
/**
275-
* Returns a subset of rows from the given dataframe for rendering.
276-
* It's used for example for dynamic pagination in Kotlin Notebook Plugin.
277-
*/
278-
public fun getRowsSubsetForRendering(
279-
dataFrameLike: Any?,
280-
startIdx: Int,
281-
endIdx: Int
282-
): DisableRowsLimitWrapper = when (dataFrameLike) {
283-
null -> throw IllegalArgumentException("Dataframe is null")
284-
else -> getRowsSubsetForRendering(convertToDataFrame(dataFrameLike), startIdx, endIdx)
285-
}
286-
287-
/**
288-
* Returns a subset of rows from the given dataframe for rendering.
289-
* It's used for example for dynamic pagination in Kotlin Notebook Plugin.
290-
*/
291-
public fun getRowsSubsetForRendering(df: AnyFrame, startIdx: Int, endIdx: Int): DisableRowsLimitWrapper =
292-
DisableRowsLimitWrapper(df.filter { it.index() in startIdx until endIdx })
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.jetbrains.kotlinx.dataframe.jupyter
2+
3+
import org.jetbrains.kotlinx.dataframe.AnyFrame
4+
import org.jetbrains.kotlinx.dataframe.api.filter
5+
6+
/**
7+
* A class with utility methods for Kotlin Notebook Plugin integration.
8+
* Kotlin Notebook Plugin is acts as a client of Kotlin Jupyter kernel and use this functionality
9+
* for dynamic pagination when rendering dataframes.
10+
* The plugin sends Kotlin following code to the kernel to evaluate
11+
* DISPLAY(KotlinNotebooksPluginUtils.getRowsSubsetForRendering(Out[x], 0, 20), "")
12+
*/
13+
public class KotlinNotebookPluginUtils {
14+
public companion object {
15+
/**
16+
* Returns a subset of rows from the given dataframe for rendering.
17+
* It's used for example for dynamic pagination in Kotlin Notebook Plugin.
18+
*/
19+
public fun getRowsSubsetForRendering(
20+
dataFrameLike: Any?,
21+
startIdx: Int,
22+
endIdx: Int
23+
): DisableRowsLimitWrapper = when (dataFrameLike) {
24+
null -> throw IllegalArgumentException("Dataframe is null")
25+
else -> getRowsSubsetForRendering(convertToDataFrame(dataFrameLike), startIdx, endIdx)
26+
}
27+
28+
/**
29+
* Returns a subset of rows from the given dataframe for rendering.
30+
* It's used for example for dynamic pagination in Kotlin Notebook Plugin.
31+
*/
32+
public fun getRowsSubsetForRendering(df: AnyFrame, startIdx: Int, endIdx: Int): DisableRowsLimitWrapper =
33+
DisableRowsLimitWrapper(df.filter { it.index() in startIdx until endIdx })
34+
}
35+
}

0 commit comments

Comments
 (0)