Skip to content

Commit 57a8f47

Browse files
Automated commit of generated code
1 parent 76665d5 commit 57a8f47

File tree

2 files changed

+78
-22
lines changed

2 files changed

+78
-22
lines changed

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/explainer/SamplesRenderingUtils.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ val WritersideStyle = DataFrameHtmlData(
3737
function sendHeight() {
3838
let totalHeight = 0;
3939
40-
document.querySelectorAll('body > details, body > br').forEach(element => {
40+
document.querySelectorAll('body > details, body > br, body > table').forEach(element => {
4141
if (element.tagName === 'DETAILS') {
4242
totalHeight += getElementHeight(element.querySelector(':scope > summary'));
4343
@@ -46,6 +46,8 @@ function sendHeight() {
4646
}
4747
} else if (element.tagName === 'BR') {
4848
totalHeight += getElementHeight(element);
49+
} else if (element.tagName === 'TABLE') {
50+
totalHeight += getElementHeight(element);
4951
}
5052
});
5153
@@ -99,11 +101,13 @@ function isElementVisible(el) {
99101
function sendInitialHeight() {
100102
let initialHeight = 0;
101103
102-
document.querySelectorAll('body > details, body > br').forEach(element => {
104+
document.querySelectorAll('body > details, body > br, body > table').forEach(element => {
103105
if (element.tagName === 'DETAILS') {
104106
initialHeight += getElementHeight(element.querySelector(':scope > summary'));
105107
} else if (element.tagName === 'BR') {
106108
initialHeight += getElementHeight(element);
109+
} else if (element.tagName === `TABLE`) {
110+
initialHeight += getElementHeight(element);
107111
}
108112
});
109113

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/Create.kt

Lines changed: 72 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package org.jetbrains.kotlinx.dataframe.samples.api
44

55
import io.kotest.matchers.shouldBe
66
import org.jetbrains.kotlinx.dataframe.AnyFrame
7+
import org.jetbrains.kotlinx.dataframe.DataColumn
78
import org.jetbrains.kotlinx.dataframe.DataFrame
89
import org.jetbrains.kotlinx.dataframe.api.DynamicDataFrameBuilder
910
import org.jetbrains.kotlinx.dataframe.api.Infer
@@ -25,13 +26,11 @@ import org.jetbrains.kotlinx.dataframe.api.toColumn
2526
import org.jetbrains.kotlinx.dataframe.api.toColumnOf
2627
import org.jetbrains.kotlinx.dataframe.api.toDataFrame
2728
import org.jetbrains.kotlinx.dataframe.api.value
28-
import org.jetbrains.kotlinx.dataframe.columns.ColumnKind
2929
import org.jetbrains.kotlinx.dataframe.explainer.TransformDataFrameExpressions
30-
import org.jetbrains.kotlinx.dataframe.kind
31-
import org.jetbrains.kotlinx.dataframe.type
3230
import org.junit.Test
3331
import java.io.File
34-
import kotlin.reflect.typeOf
32+
import kotlin.random.nextInt
33+
import kotlin.random.Random as KotlinRandom
3534

3635
class Create : TestBase() {
3736

@@ -222,6 +221,70 @@ class Create : TestBase() {
222221
// SampleEnd
223222
}
224223

224+
@Test
225+
@TransformDataFrameExpressions
226+
fun createRandomDataFrame() {
227+
// stable random + clean examples
228+
@Suppress("LocalVariableName")
229+
val Random = KotlinRandom(42)
230+
fun <T> List<T>.random() = this.random(Random)
231+
// SampleStart
232+
val categories = listOf("Electronics", "Books", "Clothing")
233+
// DataFrame with 4 columns and 7 rows
234+
(0 until 7).toDataFrame {
235+
"productId" from { "P${1000 + it}" }
236+
"category" from { categories.random() }
237+
"price" from { Random.nextDouble(10.0, 500.0) }
238+
"inStock" from { Random.nextInt(0..100) }
239+
}
240+
// SampleEnd
241+
}
242+
243+
@Test
244+
@TransformDataFrameExpressions
245+
fun createNestedRandomDataFrame() {
246+
// stable random + clean examples
247+
@Suppress("LocalVariableName")
248+
val Random = KotlinRandom(42)
249+
fun <T> List<T>.random() = this.random(Random)
250+
// SampleStart
251+
val categories = listOf("Electronics", "Books", "Clothing")
252+
// DataFrame with 5 columns and 7 rows
253+
(0 until 7).toDataFrame {
254+
"productId" from { "P${1000 + it}" }
255+
"category" from { categories.random() }
256+
"price" from { Random.nextDouble(10.0, 500.0) }
257+
258+
// Column Group
259+
"manufacturer" {
260+
"country" from { listOf("USA", "China", "Germany", "Japan").random() }
261+
"yearEstablished" from { Random.nextInt(1950..2020) }
262+
}
263+
264+
// Frame Column
265+
"reviews" from {
266+
val reviewCount = Random.nextInt(0..7)
267+
(0 until reviewCount).toDataFrame {
268+
val ratings: DataColumn<Int> = expr { Random.nextInt(1..5) }
269+
val comments = ratings.map {
270+
when (it) {
271+
5 -> listOf("Amazing quality!", "Best purchase ever!", "Highly recommend!", "Absolutely perfect!")
272+
4 -> listOf("Great product!", "Very satisfied", "Good value for money", "Would buy again")
273+
3 -> listOf("It's okay", "Does the job", "Average quality", "Neither good nor bad")
274+
2 -> listOf("Could be better", "Disappointed", "Not what I expected", "Poor quality")
275+
else -> listOf("Terrible!", "Not worth the price", "Complete waste of money", "Do not buy!")
276+
}.random()
277+
}
278+
279+
"author" from { "User${Random.nextInt(1000..10000)}" }
280+
ratings into "rating"
281+
comments into "comment"
282+
}
283+
}
284+
}
285+
// SampleEnd
286+
}
287+
225288
@Test
226289
@TransformDataFrameExpressions
227290
fun createDataFrameOfPairs() {
@@ -254,7 +317,11 @@ class Create : TestBase() {
254317
fun createDataFrameWithFill() {
255318
// SampleStart
256319
// Multiplication table
257-
dataFrameOf(1..10) { x -> (1..10).map { x * it } }
320+
(1..10).toDataFrame {
321+
(1..10).forEach { x ->
322+
"$x" from { x * it }
323+
}
324+
}
258325
// SampleEnd
259326
}
260327

@@ -330,10 +397,6 @@ class Create : TestBase() {
330397

331398
val df = persons.toDataFrame()
332399
// SampleEnd
333-
df.columnsCount() shouldBe 2
334-
df.rowsCount() shouldBe 3
335-
df["name"].type() shouldBe typeOf<String>()
336-
df["age"].type() shouldBe typeOf<Int>()
337400
}
338401

339402
@Test
@@ -353,11 +416,6 @@ class Create : TestBase() {
353416

354417
val df = students.toDataFrame(maxDepth = 1)
355418
// SampleEnd
356-
df.columnsCount() shouldBe 3
357-
df.rowsCount() shouldBe 2
358-
df["name"].kind shouldBe ColumnKind.Group
359-
df["name"]["firstName"].type() shouldBe typeOf<String>()
360-
df["scores"].kind shouldBe ColumnKind.Frame
361419
}
362420

363421
@Test
@@ -392,12 +450,6 @@ class Create : TestBase() {
392450
}
393451
}
394452
// SampleEnd
395-
df.columnsCount() shouldBe 5
396-
df.rowsCount() shouldBe 2
397-
df["name"].kind shouldBe ColumnKind.Value
398-
df["name"].type shouldBe typeOf<Name>()
399-
df["scores"].kind shouldBe ColumnKind.Frame
400-
df["summary"]["min score"].values() shouldBe listOf(3, 5)
401453
}
402454

403455
@Test

0 commit comments

Comments
 (0)