Skip to content

Commit 2a1b305

Browse files
committed
including test sources to doc processor to enable cross-references
1 parent e6ab95b commit 2a1b305

File tree

101 files changed

+15945
-186
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+15945
-186
lines changed

core/build.gradle.kts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ val addGeneratedSourcesToGit by tasks.creating(GitTask::class) {
6969

7070
// Backup the kotlin source files location
7171
val kotlinMainSources = kotlin.sourceSets.main.get().kotlin.sourceDirectories
72+
val kotlinTestSources = kotlin.sourceSets.test.get().kotlin.sourceDirectories
7273

7374
// Task to generate the processed documentation
7475
val processKDocsMain by creatingProcessDocTask(
75-
sources = kotlinMainSources.filterNot { "build/generated" in it.path }, // Exclude generated sources
76+
sources = (kotlinMainSources + kotlinTestSources) // Include both test and main sources for cross-referencing
77+
.filterNot { "build/generated" in it.path }, // Exclude generated sources
7678
) {
7779
target = file(generatedSourcesFolderName)
7880
processors = listOf(
@@ -107,8 +109,9 @@ tasks.withType<Jar> {
107109
doFirst {
108110
kotlin.sourceSets.main {
109111
kotlin.setSrcDirs(
110-
processKDocsMain.targets +
111-
kotlinMainSources.filter { "build/generated" in it.path } // Include generated sources (which were excluded above)
112+
processKDocsMain.targets
113+
.filterNot { "src/test/kotlin" in it.path || "src/test/java" in it.path } // filter out test sources again
114+
.plus(kotlinMainSources.filter { "build/generated" in it.path }) // Include generated sources (which were excluded above)
112115
)
113116
}
114117
}

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/AccessApi.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.jetbrains.kotlinx.dataframe.documentation
22

33
import org.jetbrains.kotlinx.dataframe.documentation.AccessApi.*
4-
import org.jetbrains.kotlinx.dataframe.documentation.samples.ApiLevels as ApiLevelsSample
54

65
/**
76
* ## Access APIs
@@ -123,9 +122,7 @@ internal interface AccessApi {
123122
*
124123
* For example:
125124
* ```kotlin
126-
* fun extensionProperties1() {
127-
* val df = DataFrame.read("titanic.csv")
128-
* }
125+
* val df = DataFrame.read("titanic.csv")
129126
* ```
130127
*/
131128
interface ExtensionPropertiesApi
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.jetbrains.kotlinx.dataframe
2+
3+
import org.jetbrains.kotlinx.dataframe.api.print
4+
import org.jetbrains.kotlinx.dataframe.api.schema
5+
import org.jetbrains.kotlinx.dataframe.io.renderToString
6+
import org.jetbrains.kotlinx.dataframe.types.UtilTests
7+
import java.net.URL
8+
9+
fun testResource(resourcePath: String): URL = UtilTests::class.java.classLoader.getResource(resourcePath)!!
10+
fun testCsv(csvName: String) = testResource("$csvName.csv")
11+
fun testJson(jsonName: String) = testResource("$jsonName.json")
12+
13+
fun <T : DataFrame<*>> T.toDebugString(rowsLimit: Int = 20) = """
14+
${renderToString(borders = true, title = true, columnTypes = true, valueLimit = -1, rowsLimit = rowsLimit)}
15+
16+
${schema()}
17+
""".trimIndent()
18+
19+
fun <T : DataFrame<*>> T.alsoDebug(println: String? = null, rowsLimit: Int = 20): T = apply {
20+
println?.let { println(it) }
21+
print(borders = true, title = true, columnTypes = true, valueLimit = -1, rowsLimit = rowsLimit)
22+
schema().print()
23+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.jetbrains.kotlinx.dataframe.api
2+
3+
import io.kotest.assertions.throwables.shouldThrow
4+
import io.kotest.matchers.shouldBe
5+
import org.jetbrains.kotlinx.dataframe.AnyFrame
6+
import org.junit.Test
7+
import kotlin.reflect.typeOf
8+
9+
class AddTests {
10+
11+
@Test
12+
fun `add with new`() {
13+
val x by columnOf(7, 2, 0, 3, 4, 2, 5, 0, 3, 4)
14+
val df = dataFrameOf(x)
15+
val added = df.add("Y") { if (x() == 0) 0 else (prev()?.newValue() ?: 0) + 1 }
16+
val expected = listOf(1, 2, 0, 1, 2, 3, 4, 0, 1, 2)
17+
added["Y"].values() shouldBe expected
18+
}
19+
20+
@Test
21+
fun `throw for newValue at the next row`() {
22+
val x by columnOf(7, 2, 0, 3, 4, 2, 5, 0, 3, 4)
23+
val df = dataFrameOf(x)
24+
shouldThrow<IndexOutOfBoundsException> {
25+
df.add("y") { next()?.newValue() ?: 1 }
26+
}
27+
}
28+
29+
private fun <T> AnyFrame.addValue(value: T) = add("value") { listOf(value) }
30+
31+
@Test
32+
fun `add with generic function`() {
33+
val df = dataFrameOf("a")(1).addValue(2)
34+
df["value"].type() shouldBe typeOf<List<Any?>>()
35+
}
36+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.jetbrains.kotlinx.dataframe.api
2+
3+
import io.kotest.assertions.throwables.shouldThrow
4+
import io.kotest.matchers.shouldBe
5+
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
6+
import org.junit.Test
7+
import java.lang.IllegalArgumentException
8+
9+
class CastTests {
10+
11+
@Test
12+
fun safeUnsafeCast() {
13+
@DataSchema
14+
data class Data(val a: Int, val b: String)
15+
16+
val df = dataFrameOf("a", "b", "c")(1, "s", 2)
17+
df.cast<Data>(verify = true) shouldBe df
18+
19+
shouldThrow<IllegalArgumentException> {
20+
df.convert("a").toDouble().cast<Data>(verify = true)
21+
}
22+
val converted = df.convert("a").toDouble()
23+
converted.cast<Data>(verify = false) shouldBe converted
24+
converted.cast<Data>() shouldBe converted
25+
}
26+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.jetbrains.kotlinx.dataframe.api
2+
3+
import io.kotest.matchers.shouldBe
4+
import org.jetbrains.kotlinx.dataframe.size
5+
import org.junit.Test
6+
7+
class ChunkedTests {
8+
9+
@Test
10+
fun chunkedColumnGroup() {
11+
val a by columnOf(listOf(1, 2, 3).toColumn("b"), listOf(4, 5, 6).toColumn("c"))
12+
val chunked = a.asColumnGroup().chunked(2)
13+
chunked.size shouldBe 2
14+
chunked.name() shouldBe "a"
15+
chunked[1].rowsCount() shouldBe 1
16+
}
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.jetbrains.kotlinx.dataframe.api
2+
3+
import io.kotest.matchers.shouldBe
4+
import org.junit.Test
5+
6+
class ConcatTests {
7+
8+
@Test
9+
fun `different types`() {
10+
val a by columnOf(1, 2)
11+
val b by columnOf(3.0, null)
12+
a.concat(b) shouldBe columnOf(1, 2, 3.0, null).named("a")
13+
}
14+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.jetbrains.kotlinx.dataframe.api
2+
3+
import io.kotest.matchers.shouldBe
4+
import org.junit.Test
5+
6+
class ContainsTests {
7+
8+
@Test
9+
fun `column contains`() {
10+
val col by columnOf(1, 3, 5)
11+
col.contains(3) shouldBe true
12+
col.contains(2) shouldBe false
13+
}
14+
15+
@Test
16+
fun `column group contains`() {
17+
val df = dataFrameOf("a", "b")(1, 2, 3, 4)
18+
val col = df.asColumnGroup("col")
19+
col.contains(df[0]) shouldBe true
20+
col.contains(df.update("b").withValue(0)[0]) shouldBe false
21+
}
22+
23+
@Test
24+
fun `contains column`() {
25+
val a by column<Int>()
26+
val df = dataFrameOf("a")(1, 2)
27+
(a in df) shouldBe true
28+
df.containsColumn(a) shouldBe true
29+
df.containsColumn("a") shouldBe true
30+
df.containsColumn(df["a"]) shouldBe true
31+
val b by column<Int>()
32+
(b in df) shouldBe false
33+
df.containsColumn(b) shouldBe false
34+
}
35+
36+
@Test
37+
fun `contains nested column`() {
38+
val g by columnGroup()
39+
val a by g.column<Int>()
40+
41+
val df = dataFrameOf("a")(1, 2).group("a").into("g")
42+
(a in df) shouldBe true
43+
}
44+
45+
@Test
46+
fun `row contains key`() {
47+
val a by column<Int>()
48+
val b by column<Int>()
49+
data class A(val a: Int, val b: Int)
50+
51+
val df = dataFrameOf("a")(1, 2)
52+
val row = df[0]
53+
54+
row.containsKey("a") shouldBe true
55+
row.containsKey(a) shouldBe true
56+
row.containsKey(A::a) shouldBe true
57+
(A::a in row) shouldBe true
58+
(a in row) shouldBe true
59+
60+
row.containsKey("b") shouldBe false
61+
row.containsKey(b) shouldBe false
62+
row.containsKey(A::b) shouldBe false
63+
}
64+
}

0 commit comments

Comments
 (0)