Skip to content

Commit f8b6e73

Browse files
committed
updated quickstart.kt with more compiler plugin magic
1 parent 1986248 commit f8b6e73

File tree

5 files changed

+54
-59
lines changed

5 files changed

+54
-59
lines changed

samples/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import org.gradle.kotlin.dsl.runKtlintFormatOverTestSourceSet
1616
import org.gradle.kotlin.dsl.sourceSets
1717
import org.gradle.kotlin.dsl.test
1818
import org.gradle.kotlin.dsl.testImplementation
19+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
1920

2021
plugins {
2122
java
@@ -45,7 +46,7 @@ val dependentProjects = with(projects) {
4546
)
4647
}.map { project(it.path) }
4748

48-
tasks.compileKotlin {
49+
tasks.withType<KotlinCompile> {
4950
dependentProjects.forEach {
5051
dependsOn("${it.path}:jar")
5152
}

samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/DataFrameSampleHelper.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ abstract class DataFrameSampleHelper(sampleName: String, subFolder: String = "sa
1111
subFolder,
1212
"../docs/StardustDocs/images",
1313
"../docs/StardustDocs/resources",
14-
), TestBase {
14+
),
15+
TestBase {
1516

1617
fun DataColumn<*>.saveDfHtmlSample() {
1718
toDataFrame().saveDfHtmlSample()

samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/Modify.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@ package org.jetbrains.kotlinx.dataframe.samples.api
33
import org.jetbrains.kotlinx.dataframe.DataColumn
44
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl
55
import org.jetbrains.kotlinx.dataframe.api.and
6-
import org.jetbrains.kotlinx.dataframe.api.cast
76
import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
87
import org.jetbrains.kotlinx.dataframe.api.format
98
import org.jetbrains.kotlinx.dataframe.api.getColumnIndex
10-
import org.jetbrains.kotlinx.dataframe.api.group
11-
import org.jetbrains.kotlinx.dataframe.api.into
129
import org.jetbrains.kotlinx.dataframe.api.linearBg
1310
import org.jetbrains.kotlinx.dataframe.api.max
1411
import org.jetbrains.kotlinx.dataframe.api.min
@@ -18,8 +15,6 @@ import org.jetbrains.kotlinx.dataframe.api.with
1815
import org.jetbrains.kotlinx.dataframe.samples.DataFrameSampleHelper
1916
import org.junit.Test
2017

21-
22-
2318
@Suppress("ktlint:standard:argument-list-wrapping")
2419
class Modify : DataFrameSampleHelper("operations", "modify") {
2520

samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/TestBase.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
package org.jetbrains.kotlinx.dataframe.samples.api
44

55
import io.kotest.matchers.shouldBe
6-
import org.jetbrains.kotlinx.dataframe.DataRow
6+
import org.jetbrains.kotlinx.dataframe.DataFrame
77
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
88
import org.jetbrains.kotlinx.dataframe.api.cast
99
import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
@@ -13,7 +13,7 @@ import org.jetbrains.kotlinx.dataframe.api.into
1313
@Suppress("ktlint:standard:argument-list-wrapping")
1414
interface TestBase {
1515

16-
val peopleDf
16+
val peopleDf: DataFrame<Person>
1717
get() = dataFrameOf("firstName", "lastName", "age", "city", "weight", "isHappy")(
1818
"Alice", "Cooper", 15, "London", 54, true,
1919
"Bob", "Dylan", 45, "Dubai", 87, true,

samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/guides/quickstart.kt

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -29,68 +29,56 @@ import org.jetbrains.kotlinx.kandy.letsplot.feature.layout
2929
import org.jetbrains.kotlinx.kandy.letsplot.layers.bars
3030
import org.junit.Ignore
3131
import org.junit.Test
32+
import java.net.URL
3233

3334
class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
3435

3536
@DataSchema
36-
interface Repositories : SelectedRepositories {
37-
val html_url: java.net.URL
37+
interface Repositories {
38+
val html_url: URL
3839
val watchers: Int
39-
}
40-
41-
@DataSchema
42-
interface SelectedRepositories {
4340
val full_name: String
4441
val stargazers_count: Int
4542
val topics: String
4643
}
4744

48-
@DataSchema
49-
interface RenamedSelectedRepositories {
50-
val name: String
51-
val starsCount: Int
52-
val topics: String
53-
}
54-
55-
@DataSchema
56-
interface UpdatedRepositories {
57-
val name: String
58-
val starsCount: Int
59-
val topics: List<String>
60-
}
61-
62-
@DataSchema
63-
interface IsIntellijRepositories {
64-
val name: String
65-
val starsCount: Int
66-
val topics: List<String>
67-
val isIntellij: Boolean
68-
}
69-
7045
private val df = DataFrame.readCsv(
7146
"https://raw.githubusercontent.com/Kotlin/dataframe/master/data/jetbrains_repositories.csv",
7247
).cast<Repositories>()
7348

74-
private val dfSelected = df.select { full_name and stargazers_count and topics }.cast<SelectedRepositories>()
75-
private val dfFiltered = dfSelected.filter { stargazers_count >= 1000 }
76-
private val dfRenamed = dfFiltered.rename { full_name }.into("name")
77-
// And "stargazers_count" into "starsCount"
78-
.rename { stargazers_count }.into("starsCount")
79-
.cast<RenamedSelectedRepositories>()
80-
private val dfUpdated = dfRenamed
81-
// Update "name" values with only its second part (after '/')
82-
.update { name }.with { it.split("/")[1] }
83-
// Convert "topics" `String` values into `List<String>` by splitting:
84-
.convert { topics }.with { it.removePrefix("[").removeSuffix("]").split(", ") }
85-
.cast<UpdatedRepositories>()
86-
87-
private val dfWithIsIntellij = dfUpdated.add("isIntellij") {
88-
name.contains("intellij") || "intellij" in topics
89-
}.cast<IsIntellijRepositories>()
90-
private val groupedByIsIntellij = dfWithIsIntellij.groupBy { isIntellij }
91-
private val dfTop10 = dfWithIsIntellij
92-
// Sort by "starsCount" value descending
93-
.sortByDesc { starsCount }.take(10)
49+
private fun getDfSelected() = df.select { full_name and stargazers_count and topics }
50+
51+
private fun getDfFiltered() =
52+
getDfSelected()
53+
.filter { stargazers_count >= 1000 }
54+
55+
private fun getDfRenamed() =
56+
getDfFiltered()
57+
.rename { full_name }.into("name")
58+
// And "stargazers_count" into "starsCount"
59+
.rename { stargazers_count }.into("starsCount")
60+
61+
private fun getDfUpdated() =
62+
getDfRenamed()
63+
// Update "name" values with only its second part (after '/')
64+
.update { name }.with { it.split("/")[1] }
65+
// Convert "topics" `String` values into `List<String>` by splitting:
66+
.convert { topics }.with { it.removePrefix("[").removeSuffix("]").split(", ") }
67+
68+
private fun getDfWithIsIntellij() =
69+
getDfUpdated()
70+
.add("isIntellij") {
71+
name.contains("intellij") || "intellij" in topics
72+
}
73+
74+
private fun getGroupedByIsIntellij() =
75+
getDfWithIsIntellij()
76+
.groupBy { isIntellij }
77+
78+
private fun getDfTop10() =
79+
getDfWithIsIntellij()
80+
// Sort by "starsCount" value descending
81+
.sortByDesc { starsCount }.take(10)
9482

9583
@Test
9684
fun notebook_test_quickstart_2() {
@@ -129,6 +117,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
129117

130118
@Test
131119
fun notebook_test_quickstart_6() {
120+
val dfSelected = getDfSelected()
132121
// SampleStart
133122
// Keep only rows where "stargazers_count" value is more than 1000
134123
val dfFiltered = dfSelected.filter { stargazers_count >= 1000 }
@@ -139,6 +128,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
139128

140129
@Test
141130
fun notebook_test_quickstart_7() {
131+
val dfFiltered = getDfFiltered()
142132
// SampleStart
143133
// Rename "full_name" column into "name"
144134
val dfRenamed = dfFiltered.rename { full_name }.into("name")
@@ -151,6 +141,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
151141

152142
@Test
153143
fun notebook_test_quickstart_8() {
144+
val dfRenamed = getDfRenamed()
154145
// SampleStart
155146
val dfUpdated = dfRenamed
156147
// Update "name" values with only its second part (after '/')
@@ -164,13 +155,15 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
164155

165156
@Test
166157
fun notebook_test_quickstart_9() {
158+
val dfUpdated = getDfUpdated()
167159
// SampleStart
168160
dfUpdated.topics.type()
169161
// SampleEnd
170162
}
171163

172164
@Test
173165
fun notebook_test_quickstart_10() {
166+
val dfUpdated = getDfUpdated()
174167
// SampleStart
175168
// Add a `Boolean` column indicating whether the `name` contains the "intellij" substring
176169
// or the topics include "intellij".
@@ -184,14 +177,17 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
184177

185178
@Test
186179
fun notebook_test_quickstart_11() {
180+
val dfWithIsIntellij = getDfWithIsIntellij()
187181
// SampleStart
182+
val groupedByIsIntellij = dfWithIsIntellij.groupBy { isIntellij }
188183
groupedByIsIntellij
189184
// SampleEnd
190185
.saveDfHtmlSample()
191186
}
192187

193188
@Test
194189
fun notebook_test_quickstart_12() {
190+
val groupedByIsIntellij = getGroupedByIsIntellij()
195191
// SampleStart
196192
groupedByIsIntellij.count()
197193
// SampleEnd
@@ -200,8 +196,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
200196

201197
@Test
202198
fun notebook_test_quickstart_13() {
203-
// issue #1454
204-
val groupedByIsIntellij = dfWithIsIntellij.groupBy { isIntellij }
199+
val groupedByIsIntellij = getGroupedByIsIntellij()
205200
// SampleStart
206201
groupedByIsIntellij.aggregate {
207202
// Compute sum and max of "starsCount" within each group into "sumStars" and "maxStars" columns
@@ -214,6 +209,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
214209

215210
@Test
216211
fun notebook_test_quickstart_14() {
212+
val dfWithIsIntellij = getDfWithIsIntellij()
217213
// SampleStart
218214
val dfTop10 = dfWithIsIntellij
219215
// Sort by "starsCount" value descending
@@ -225,6 +221,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
225221

226222
@Test
227223
fun notebook_test_quickstart_16() {
224+
val dfTop10 = getDfTop10()
228225
// SampleStart
229226
dfTop10.plot {
230227
bars {
@@ -241,6 +238,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
241238
@Ignore
242239
@Test
243240
fun notebook_test_quickstart_17() {
241+
val dfWithIsIntellij = getDfWithIsIntellij()
244242
// SampleStart
245243
dfWithIsIntellij.writeExcel("jb_repos.xlsx")
246244
// SampleEnd

0 commit comments

Comments
 (0)