init research
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
class OuterClass
|
||||
|
||||
@org.jetbrains.kotlinx.dataframe.annotations.DataSchema(isOpen = false)
|
||||
interface Hello {
|
||||
val name: String
|
||||
val `test name`: InnerClass
|
||||
val nullableProperty: Int?
|
||||
val a: () -> Unit
|
||||
val d: List<List<*>>
|
||||
|
||||
class InnerClass
|
||||
}
|
||||
|
||||
val ColumnsContainer<Hello>.col1: DataColumn<String> get() = name
|
||||
val ColumnsContainer<Hello>.col2: DataColumn<Hello.InnerClass> get() = `test name`
|
||||
val ColumnsContainer<Hello>.col3: DataColumn<Int?> get() = nullableProperty
|
||||
val ColumnsContainer<Hello>.col4: DataColumn<() -> Unit> get() = a
|
||||
val ColumnsContainer<Hello>.col5: DataColumn<List<List<*>>> get() = d
|
||||
|
||||
val DataRow<Hello>.row1: String get() = name
|
||||
val DataRow<Hello>.row2: Hello.InnerClass get() = `test name`
|
||||
val DataRow<Hello>.row3: Int? get() = nullableProperty
|
||||
val DataRow<Hello>.row4: () -> Unit get() = a
|
||||
val DataRow<Hello>.row5: List<List<*>> get() = d
|
||||
|
||||
fun box(): String {
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
interface Schema {
|
||||
val a: Int
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val res = dataFrameOf("a")(1)
|
||||
.cast<Schema>()
|
||||
.add("wwffffwwehirbwerffwffwffwfffffwfffwfwfwfaw") { 42 }
|
||||
|
||||
res.wwffffwwehirbwerffwffwffwfffffwfffwfwfwfaw.print()
|
||||
res.a.print()
|
||||
|
||||
val b = res.convert { a }.with { it.toString() }
|
||||
|
||||
b.a
|
||||
|
||||
// val res1 = res.conv
|
||||
//res.filter { it }
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf("a")(1).add {
|
||||
"id" from { it }
|
||||
"group" {
|
||||
"a" from { it }
|
||||
}
|
||||
group("group1") {
|
||||
"b" from { it }
|
||||
}
|
||||
}
|
||||
|
||||
df.group.a
|
||||
df.group1.b
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf("a")(1).addId()
|
||||
val i: DataColumn<Int> = df.id
|
||||
val i1: DataColumn<Int> = dataFrameOf("a")(1).addId("i").i
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val row = dataFrameOf("a" to List(10) { it }).aggregate {
|
||||
maxOf { a } into "max"
|
||||
minOf { a } into "min"
|
||||
}
|
||||
val i: Int = row.max
|
||||
val i1: Int = row.min
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf("i", "group")(1, dataFrameOf("a", "b")(111, 222))
|
||||
val aggregated1 = df.asGroupBy { group }.aggregate { maxOf { a } into "max" }
|
||||
val aggregated2 = df.asGroupBy().aggregate { maxOf { a } into "max" }
|
||||
|
||||
val i: Int = aggregated1.max[0]
|
||||
|
||||
compareSchemas(aggregated1, aggregated2)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
import java.net.URI
|
||||
|
||||
fun box(): String {
|
||||
val sample = dataFrameOf("full_name", "html_url", "stargazers_count", "topics", "watchers")(
|
||||
"JetBrains/JPS", URI("https://github.com/JetBrains/JPS").toURL(), 23, "[]", 23
|
||||
)
|
||||
|
||||
val organizations = listOf("https://raw.githubusercontent.com/Kotlin/dataframe/master/data/jetbrains_repositories.csv")
|
||||
organizations.forEach { organization ->
|
||||
val df = DataFrame.readCSV(organization).castTo(sample)
|
||||
println(organizations)
|
||||
println("Repositories: ${df.count()}")
|
||||
println("Top 10:")
|
||||
df.sortBy { stargazers_count.desc() }.take(10).print()
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
import java.io.File
|
||||
|
||||
private fun convert(data: List<String>) = data.map { it.split(":") }.toDataFrame {
|
||||
"part1" from { it[0] }
|
||||
"part2" from { it[1].toInt() }
|
||||
"part3" from { it[2] }
|
||||
}
|
||||
|
||||
fun serialize(data: List<String>, destination: File) {
|
||||
convert(data).writeJson(destination)
|
||||
}
|
||||
|
||||
fun deserializeAndUse(file: File) {
|
||||
val df = DataFrame.readJson(file).castTo(schemaFrom = ::convert)
|
||||
df.part1.print()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val file = File.createTempFile("temp", "json")
|
||||
serialize(listOf("b:1:abc", "c:2:bca"), file)
|
||||
deserializeAndUse(file)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import kotlin.reflect.*
|
||||
import kotlin.reflect.full.*
|
||||
|
||||
inline fun <reified T> runtimeSchema(row: DataRow<T>) = (typeOf<T>().classifier as KClass<*>).memberProperties.associateBy { it.name }
|
||||
inline fun <reified T> runtimeSchema(row: DataFrame<T>) = (typeOf<T>().classifier as KClass<*>).memberProperties.associateBy { it.name }
|
||||
fun <T> Map<String, T>.col(s: String) = get(s)!!
|
||||
|
||||
@DataSchema
|
||||
class Record(val string: String)
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf(Record("abc"))
|
||||
val df1 = df.add("row") {
|
||||
val row = dataFrameOf(Record("")).first()
|
||||
row.takeIf { index() % 2 == 0 }
|
||||
}
|
||||
|
||||
require(runtimeSchema(df1.row[0]).col("string").returnType == typeOf<String?>())
|
||||
|
||||
val row = dataFrameOf(Record(""))
|
||||
.add("int") { 1 }
|
||||
.add("double") { 3.0 }
|
||||
.add("char") { 'c' }
|
||||
.group { int and double }.into("g")
|
||||
.group { g and char }.into("f")
|
||||
.first()
|
||||
|
||||
val df2 = df.add("row") {
|
||||
row.takeIf { index() % 2 == 0 }
|
||||
}
|
||||
|
||||
require(runtimeSchema(df2.row.f.g[0]).col("int").returnType == typeOf<Int?>())
|
||||
require(runtimeSchema(df2.row.f[0]).col("char").returnType == typeOf<Char?>())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
|
||||
@DataSchema
|
||||
data class Record(val str: String)
|
||||
|
||||
class A
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf(Record("abc"))
|
||||
val df1 = listOf(A()).toDataFrame {
|
||||
"dataRow" from { df.first() }
|
||||
"dataFrame" from { df }
|
||||
}
|
||||
val a: String = df1.dataRow.str[0]
|
||||
val b: String = df1.dataFrame[0].str[0]
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
data class Record(val a: String, val b: Int)
|
||||
|
||||
fun box(): String {
|
||||
val df = List(10) { Record(it.toString(), it) }.let { dataFrameOf(*it.toTypedArray()) }
|
||||
val group = df.group { a and b }.into("c")
|
||||
val df1 = group.c.add("d") { 1 }
|
||||
df1.a
|
||||
df1.b
|
||||
df1.d
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
data class Record(
|
||||
@ColumnName("a")
|
||||
val abc: String,
|
||||
)
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf("a")("1").cast<Record>()
|
||||
df.abc
|
||||
|
||||
val df1 = df.add("b") { 1 }
|
||||
df1.a
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf("a.b")(1)
|
||||
df.`a b`
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val group = columnOf(
|
||||
"c" to columnOf("2"),
|
||||
"d" to columnOf(123),
|
||||
)
|
||||
val str: DataColumn<String> = group.c
|
||||
val i: DataColumn<Int> = group.d
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
data class Record(val id: String, val b: Int)
|
||||
|
||||
public data class NameValuePair<V>(val name: String, val value: V)
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf(Record("1", 1), Record("2", 123), Record("3", 321))
|
||||
val df1 = df.first().transpose().dropNulls { value }
|
||||
val v: Any = df1.value[0]
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf(
|
||||
"value" to listOf(1, 2, 3, 3),
|
||||
"type" to listOf("a", "b", "a", "b")
|
||||
)
|
||||
val gb = df.groupBy { expr { "Category: ${type.uppercase()}" } named "category" }
|
||||
val categoryKey = gb.keys.category
|
||||
|
||||
val dfWithCategory = gb.concatWithKeys()
|
||||
|
||||
val category: DataColumn<String> = dfWithCategory.category
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
interface Repo {
|
||||
val name: String
|
||||
val url: String
|
||||
}
|
||||
//
|
||||
@DataSchema
|
||||
data class Type(val name: String, val vararg: Boolean)
|
||||
|
||||
fun box() = "OK"
|
||||
@@ -0,0 +1,14 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val res = dataFrameOf("a")(1, 2, 3).convert { a }.asColumn { it.convertToString() }
|
||||
val str: DataColumn<String> = res.a
|
||||
|
||||
val res1 = dataFrameOf("a")(1).convert { a }.asColumn { dataFrameOf("b", "c")(2, 3.0).asColumnGroup() }
|
||||
val i: DataColumn<Int> = res1.a.b
|
||||
val d: DataColumn<Double> = res1.a.c
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
data class Sessions(
|
||||
val roomId: List<Int>
|
||||
)
|
||||
|
||||
@DataSchema
|
||||
data class Rooms(
|
||||
val id: Int,
|
||||
val sort: Int,
|
||||
val name: String,
|
||||
)
|
||||
|
||||
class Aaa(val a: List<Rooms>)
|
||||
|
||||
fun box(): String {
|
||||
val rooms = dataFrameOf(Rooms(1, 2, "n"))
|
||||
val sessions = dataFrameOf(Sessions(listOf(1, 2)))
|
||||
|
||||
val df = sessions.convert { roomId }.with {
|
||||
listOf(Aaa(listOf(Rooms(1, 2, "n")))).toDataFrame(maxDepth = 2)
|
||||
}
|
||||
|
||||
df.roomId[0].a[0].id
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
import kotlinx.datetime.*
|
||||
|
||||
fun box(): String {
|
||||
val daysToStandardMillis = 24 * 60 * 60 * 1000L * 366
|
||||
val df = dataFrameOf("a")(60L * 1000L + daysToStandardMillis).convert { a }.toLocalDateTime(TimeZone.UTC)
|
||||
val localDateTime: LocalDateTime = df.a[0]
|
||||
|
||||
val df1 = dataFrameOf("a")(60L * 1000L + daysToStandardMillis, null).convert { a }.toLocalDateTime(TimeZone.UTC)
|
||||
val localDateTime1: LocalDateTime? = df1.a[0]
|
||||
|
||||
val df2 = dataFrameOf("a")(123).convert { a }.toStr()
|
||||
val str: String = df2.a[0]
|
||||
|
||||
val df3 = dataFrameOf("a")(123, null).convert { a }.toStr()
|
||||
df3.compareSchemas(strict = true)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf("col")("1", "2").convert { col }.to<Int>()
|
||||
val i: Int = df.col[0]
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
compareSchemas(
|
||||
df.select { name and age },
|
||||
df.select { allBefore { city } },
|
||||
df.select { allBefore(city) },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { name and age },
|
||||
df.select { allUpTo { age } },
|
||||
df.select { allUpTo(age) },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { weight and isHappy },
|
||||
df.select { allAfter { city } },
|
||||
df.select { allAfter(city) },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { weight and isHappy },
|
||||
df.select { allFrom { weight } },
|
||||
df.select { allFrom(weight) },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { name and age and city and weight and isHappy },
|
||||
df.select { all() }
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { name.firstName and name.lastName },
|
||||
df.select { name.allCols() },
|
||||
df.select { name.allCols().all() },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { weight and isHappy },
|
||||
df.select { all().allAfter(city) },
|
||||
// df.select { all().allAfter { city } },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { age },
|
||||
df.select { colsOf<Int?>().allBefore(weight) },
|
||||
df.select { allBefore(weight).colsOf<Int?>() },
|
||||
)
|
||||
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
compareSchemas(
|
||||
df.select { name },
|
||||
df.select { colGroups() },
|
||||
df.select { nameContains("e").colGroups() },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
dfGroup.select { name.firstName },
|
||||
dfGroup.select { name.colsNameContains("Name").colGroups() },
|
||||
)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
compareSchemas(
|
||||
df.select { cols(name, age, city, weight, isHappy) },
|
||||
df.select { all() },
|
||||
)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df1 = df.select { name }
|
||||
|
||||
compareSchemas(
|
||||
df1.select { name.firstName and name.lastName },
|
||||
df1.select { name.colsAtAnyDepth() },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df1.select { name and name.firstName and name.lastName },
|
||||
df1.select { colsAtAnyDepth() },
|
||||
df1.select { nameStartsWith("name").colsAtAnyDepth() },
|
||||
)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
compareSchemas(
|
||||
df.select { city },
|
||||
df.select { colsOf<String?>() },
|
||||
df.select { all().colsOf<String?>() },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { name.firstName and name.lastName },
|
||||
df.select { name.colsOf<String>() },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { name },
|
||||
df.select { colsOf<AnyRow>() }
|
||||
)
|
||||
|
||||
val df1 = dataFrameOf("nestedDf")(dataFrameOf("a", "b")(1, 2))
|
||||
compareSchemas(
|
||||
df1.select { nestedDf },
|
||||
df1.select { colsOf<AnyFrame>() }
|
||||
)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
compareSchemas(
|
||||
df.select { age },
|
||||
df.select { nameContains("age") },
|
||||
df.select { nameContains("AGE", ignoreCase = true) },
|
||||
df.select { all().nameContains("age") },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { name.firstName },
|
||||
df.select { name.colsNameContains("first") },
|
||||
df.select { name.colsNameContains("FIRST", ignoreCase = true) },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { age },
|
||||
df.select { nameStartsWith("age") },
|
||||
df.select { nameStartsWith("AGE", ignoreCase = true) },
|
||||
df.select { all().nameStartsWith("age") },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { name.firstName },
|
||||
df.select { name.colsNameStartsWith("first") },
|
||||
df.select { name.colsNameStartsWith("FIRST", ignoreCase = true) },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { name.firstName and name.lastName },
|
||||
df.select { name.colsNameEndsWith("Name") },
|
||||
df.select { name.colsNameEndsWith("NAME", ignoreCase = true) },
|
||||
)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
compareSchemas(
|
||||
df.select { age and city and weight },
|
||||
df.select { age..weight },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { name.firstName and name.lastName },
|
||||
df.select { name.firstName..name.lastName }
|
||||
)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
compareSchemas(
|
||||
df.select { name.lastName },
|
||||
df.select { name.dropCols(1) },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { name.firstName },
|
||||
df.select { name.dropLastCols(1) },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { weight and isHappy },
|
||||
df.select { drop(3) },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { name and age },
|
||||
df.select { dropLast(3) },
|
||||
)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
compareSchemas(
|
||||
df.select { name },
|
||||
df.select { first() },
|
||||
df.select { nameStartsWith("name").first() },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { name.firstName },
|
||||
df.select { name.firstCol() },
|
||||
)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df1 = dataFrameOf("a", "b", "frameCol")(1, 2, dataFrameOf("e", "f")(3, 4))
|
||||
|
||||
compareSchemas(
|
||||
df1.select { frameCol },
|
||||
df1.select { frameCols() },
|
||||
df1.select { nameContains("a").frameCols() },
|
||||
)
|
||||
|
||||
val into = df1.group { a and frameCol }.into("c")
|
||||
compareSchemas(
|
||||
into.select { c.frameCol },
|
||||
into.select { c.frameCols() },
|
||||
)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
compareSchemas(
|
||||
df.select { isHappy },
|
||||
df.select { last() },
|
||||
df.select { nameStartsWith("is").last() },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { name.lastName },
|
||||
df.select { name.lastCol() },
|
||||
)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df1 = df.select { expr { age } into "age2" }
|
||||
val i1: Int = df1.age2[0]
|
||||
|
||||
val df2 = dataFrameOf("lists")(listOf(1, 2), listOf(3)).explode { lists into "int" }
|
||||
val i2: Int = df2.int[0]
|
||||
|
||||
df.select { age named "age2" }.compareSchemas(strict = true)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf(
|
||||
"a" to listOf(1),
|
||||
"b" to listOf(1),
|
||||
).group { a and b }.into("gr")
|
||||
val res = df.select { gr.select { a and b } }
|
||||
res.a
|
||||
res.b
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
compareSchemas(
|
||||
df.select { name },
|
||||
df.select { name }.select { single() },
|
||||
df.select { nameStartsWith("name").single() },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { name.firstName },
|
||||
df.remove { name.lastName }.select { name.singleCol() },
|
||||
)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
compareSchemas(
|
||||
df.select { name.firstName },
|
||||
df.select { name.takeCols(1) },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { name.lastName },
|
||||
df.select { name.takeLastCols(1) },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { name and age and city },
|
||||
df.select { take(3) },
|
||||
df.select { all().take(3) },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { city and weight and isHappy },
|
||||
df.select { all().takeLast(3) },
|
||||
df.select { takeLast(3) },
|
||||
)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
compareSchemas(
|
||||
df.select { age and city and weight and isHappy },
|
||||
df.select { all().valueCols() },
|
||||
df.select { valueCols() },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { name.firstName and name.lastName },
|
||||
df.select { name.valueCols() },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
df.select { age and weight },
|
||||
df.select { nameContains("e").valueCols() },
|
||||
)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
compareSchemas(
|
||||
df.select { name and age and isHappy },
|
||||
df.select { withoutNulls() },
|
||||
df.select { all().withoutNulls() },
|
||||
)
|
||||
|
||||
compareSchemas(
|
||||
dfGroup.select { name.firstName.firstName },
|
||||
dfGroup.select { name.firstName.colsWithoutNulls() },
|
||||
)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
data class Person(val firstName: String, val lastName: String, val age: Int, val city: String?)
|
||||
|
||||
@DataSchema
|
||||
data class Group(val id: String, val participants: List<Person>)
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf(
|
||||
Group("1", listOf(
|
||||
Person("Alice", "Cooper", 15, "London"),
|
||||
Person("Bob", "Dylan", 45, "Dubai")
|
||||
)),
|
||||
Group("2", listOf(
|
||||
Person("Charlie", "Daniels", 20, "Moscow"),
|
||||
Person("Charlie", "Chaplin", 40, "Milan"),
|
||||
)),
|
||||
)
|
||||
|
||||
df.compareSchemas()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf(
|
||||
"a" to columnOf("1"),
|
||||
"b" to columnOf(
|
||||
"c" to columnOf("2"),
|
||||
),
|
||||
"d" to columnOf(dataFrameOf("a")(123)),
|
||||
"gr" to listOf("1").toDataFrame().asColumnGroup(),
|
||||
)
|
||||
val str: DataColumn<String> = df.a
|
||||
val str1: DataColumn<String> = df.b.c
|
||||
val i: DataColumn<Int> = df.d[0].a
|
||||
val str2: DataColumn<String> = df.gr.value
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf(
|
||||
Pair("a", listOf(1, 2))
|
||||
"b" to listOf("str1", "str2"),
|
||||
)
|
||||
val i: Int = df.a[0]
|
||||
val str: String = df.b[0]
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf("a")(1, 2, 3)
|
||||
val i: Int = df.a[0]
|
||||
|
||||
val df1 = dataFrameOf("a", "b")({ 1 }, 2)
|
||||
val i1: Int = df1.a[0].invoke()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
class Schema(
|
||||
val a: Int,
|
||||
val b: String
|
||||
)
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf(Schema(1, "foo")).append(Schema(2, "bar"))
|
||||
df.print()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
interface Schema {
|
||||
val a: Int
|
||||
val b: String
|
||||
}
|
||||
|
||||
fun box() = "OK"
|
||||
@@ -0,0 +1,31 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
interface Schema {
|
||||
val i: Int
|
||||
val fff: String
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val df = dataFrameOf("i", "fff")(1, "321").cast<Schema>()
|
||||
println(df.i)
|
||||
|
||||
val df1 = df.add("ca") { 423 }
|
||||
val res = df1.ca
|
||||
df1.filter { it.ca == 12 }
|
||||
|
||||
`Name is evaluated to age`(dataFrameOf("a")(123).cast())
|
||||
}
|
||||
|
||||
interface Cars
|
||||
|
||||
fun `Name is evaluated to age`(df: DataFrame<Cars>) {
|
||||
val df1 = df.add("age") { 2022 }
|
||||
val col = df1.age
|
||||
println(col)
|
||||
}
|
||||
|
||||
fun box() = "OK"
|
||||
@@ -0,0 +1,45 @@
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.time.temporal.ChronoUnit
|
||||
import java.time.temporal.Temporal
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun <T, V : Temporal> DataRow<T>.diff(unit: ChronoUnit, expression: RowExpression<T, V>): Long? = prev()?.let { p -> unit.between(expression(p, p), expression(this, this)) }
|
||||
|
||||
/**
|
||||
char,level,race,charclass,zone,guild,timestamp
|
||||
59425,1,Orc,Rogue,Orgrimmar,165,01/01/08 00:02:04
|
||||
65494,9,Orc,Hunter,Durotar,-1,01/01/08 00:02:04
|
||||
*/
|
||||
@DataSchema
|
||||
interface ActivePlayer {
|
||||
val char: Int
|
||||
val level: Int
|
||||
val race: String
|
||||
val charclass: String
|
||||
val zone: String
|
||||
val guild: Int
|
||||
val timestamp: String
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val df = @DisableInterpretation DataFrame.readDelimStr("""
|
||||
char,level,race,charclass,zone,guild,timestamp
|
||||
59425,1,Orc,Rogue,Orgrimmar,165,01/01/08 00:02:04
|
||||
65494,9,Orc,Hunter,Durotar,-1,01/01/08 00:02:04
|
||||
""".trimIndent())
|
||||
val df1 = df.cast<ActivePlayer>()
|
||||
|
||||
val format = DateTimeFormatter.ofPattern("MM/dd/yy HH:mm:ss")
|
||||
val df2 = df1
|
||||
.convert { timestamp }.with { LocalDateTime.parse(it, format) }
|
||||
.sortBy { char and timestamp }
|
||||
.add("tsDiff") { diff(ChronoUnit.MINUTES) { timestamp }?.let { it > 20 } ?: true }
|
||||
.add("charDiff") { diffOrNull { char }?.let { it != 0 } ?: true }
|
||||
|
||||
df2.print()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val personsDf = dataFrameOf("name", "age", "city", "weight", "height", "yearsToRetirement")(
|
||||
"Alice", 15, "London", 99.5, "1.85", 50,
|
||||
"Bob", 20, "Paris", 140.0, "1.35", 45,
|
||||
"Charlie", 100, "Dubai", 75.0, "1.95", 0,
|
||||
"Rose", 1, "Moscow", 45.33, "0.79", 64,
|
||||
"Dylan", 35, "London", 23.4, "1.83", 30,
|
||||
"Eve", 40, "Paris", 56.72, "1.85", 25,
|
||||
"Frank", 55, "Dubai", 78.9, "1.35", 10,
|
||||
"Grace", 29, "Moscow", 67.8, "1.65", 36,
|
||||
"Hank", 60, "Paris", 80.22, "1.75", 5,
|
||||
"Isla", 22, "London", 75.1, "1.85", 43,
|
||||
)
|
||||
|
||||
val res = personsDf.distinct { name and age }
|
||||
res.name
|
||||
res.age
|
||||
res.compareSchemas()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf(
|
||||
"a" to listOf(1, null, 3),
|
||||
"b" to listOf(null, 5, 6)
|
||||
)
|
||||
val df1 = df.dropNA { a and b }
|
||||
df1.compareSchemas(strict = true)
|
||||
|
||||
val df2 = df.dropNA(whereAllNA = true) { a and b }
|
||||
df2.compareSchemas(strict = true)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
data class Nested(val i: Double?)
|
||||
|
||||
data class Record(val a: String?, val b: Int?, val nested: Nested)
|
||||
|
||||
fun box(): String {
|
||||
val df = listOf(Record("112", 42, Nested(3.0))).toDataFrame(maxDepth = 1)
|
||||
df.dropNulls { a and b }
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// FILE: Test.kt
|
||||
import kotlin.random.Random
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
interface Schema {
|
||||
val a: Int
|
||||
}
|
||||
|
||||
@DataSchema
|
||||
interface Log {
|
||||
val timestamp: Long
|
||||
val message: String
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val res = dataFrameOf("a")(1)
|
||||
.cast<Schema>()
|
||||
.add("ba") { 42 }
|
||||
|
||||
res.ba.print()
|
||||
res.a.print()
|
||||
|
||||
val a = res.convert { a }.with { it.digitToChar() }
|
||||
|
||||
val str: DataColumn<Char> = a.a
|
||||
print(str)
|
||||
}
|
||||
|
||||
// FILE: duplicatedSignature.kt
|
||||
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
interface ActivePlayer {
|
||||
val char: Int
|
||||
val level: Int
|
||||
val race: String
|
||||
val charclass: String
|
||||
val zone: String
|
||||
val guild: Int
|
||||
val timestamp: String
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf("char", "level", "race", "charclass", "zone", "guild", "timestamp")(59425,1,"Orc","Rogue","Orgrimmar",165,"01/01/08 00:02:04").cast<ActivePlayer>(verify = true)
|
||||
val format = DateTimeFormatter.ofPattern("MM/dd/yy HH:mm:ss")
|
||||
val df1 = df
|
||||
.convert { timestamp }.with { LocalDateTime.parse(it, format)!! }
|
||||
|
||||
df1.print()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package dataframe
|
||||
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.columns.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
data class MyRecordModifiedStep2(
|
||||
val group: Group,
|
||||
val str: kotlin.String
|
||||
) {
|
||||
@DataSchema
|
||||
data class Group(
|
||||
val a: kotlin.String,
|
||||
val length: kotlin.Int
|
||||
)
|
||||
}
|
||||
|
||||
@DataSchema
|
||||
data class MyRecordModified(
|
||||
val group: Group
|
||||
) {
|
||||
@DataSchema
|
||||
data class Group(
|
||||
val a: kotlin.String,
|
||||
val length: kotlin.Int
|
||||
)
|
||||
}
|
||||
|
||||
@DataSchema
|
||||
data class Group1(
|
||||
val a: kotlin.String,
|
||||
)
|
||||
|
||||
@DataSchema
|
||||
data class Group2(
|
||||
val a: kotlin.String,
|
||||
)
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf(MyRecordModified(MyRecordModified.Group("a", 123)))
|
||||
// need to trigger JVM classloading so duplicated signature error can appear
|
||||
df.group.a
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf("timestamps")(listOf(100, 113, 140), listOf(400, 410, 453))
|
||||
val df1 = df.explode { timestamps }
|
||||
val timestamps: DataColumn<Int> = df1.timestamps
|
||||
timestamps.print()
|
||||
|
||||
|
||||
val df2 = dataFrameOf("a", "b")(listOf(100, 113, 140), listOf(400, 410))
|
||||
val df3 = df2.explode { a and b }
|
||||
// exploding multiple columns will introduce nulls
|
||||
df3.print()
|
||||
// compiler needs to play safe and make both selected columns nullable
|
||||
df3.compileTimeSchema().columns.let {
|
||||
assert(it["a"]!!.nullable)
|
||||
assert(it["b"]!!.nullable)
|
||||
}
|
||||
// compile time schema is still compatible with runtime
|
||||
df3.compareSchemas()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf(
|
||||
"achievements" to List(2) { dataFrameOf("order")(1, 2) }
|
||||
)
|
||||
|
||||
val df1 = df.explode { achievements }
|
||||
df1.achievements.order
|
||||
return "OK"
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
data class Record(val id: String, val b: Int)
|
||||
|
||||
public data class NameValuePair<V>(val name: String, val value: V)
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf(Record("1", 1), Record("2", 123), Record("3", 321))
|
||||
val df1 = df.first().transpose().add("c") { 1 }
|
||||
df1.name
|
||||
df1.value
|
||||
df1.c
|
||||
return "OK"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
data class Record(val id: String, val b: Int)
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf(Record("1", 1), Record("2", 123), Record("3", 321))
|
||||
val df1 = listOf("1", "2", "3").toDataFrame().join(df) { value match right.id }
|
||||
val col: DataColumn<String> = df1.value
|
||||
return "OK"
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
class Bridge(val type: Type,
|
||||
val approximation: String,
|
||||
val converter: String,
|
||||
val lens: String,
|
||||
val supported: Boolean = false) : DataRowSchema
|
||||
|
||||
@DataSchema
|
||||
data class Type(val name: String, val vararg: Boolean)
|
||||
|
||||
@DataSchema
|
||||
class Parameter(
|
||||
val name: String,
|
||||
val returnType: Type,
|
||||
val defaultValue: String?,
|
||||
) : DataRowSchema
|
||||
|
||||
@DataSchema
|
||||
class Function(
|
||||
val receiverType: String,
|
||||
val function: String,
|
||||
val functionReturnType: Type,
|
||||
val parameters: List<Parameter>
|
||||
) : DataRowSchema {
|
||||
}
|
||||
|
||||
|
||||
@DataSchema
|
||||
class RefinedFunction(
|
||||
val receiverType: String,
|
||||
val function: String,
|
||||
val functionReturnType: Type,
|
||||
val parameters: List<Parameter>,
|
||||
val startingSchema: Parameter
|
||||
) : DataRowSchema
|
||||
|
||||
fun DataFrame<Function>.refine(bridges: DataFrame<Bridge>) {
|
||||
val functions = this
|
||||
val df1 = functions.join(bridges) {
|
||||
functions.functionReturnType.name.match(right.type.name)
|
||||
}
|
||||
val col: DataColumn<DataFrame<*>> = df1.parameters
|
||||
}
|
||||
|
||||
fun box(): String = "OK"
|
||||
@@ -0,0 +1,11 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf("a", "b")(1, null, null, "")
|
||||
val df1 = df.fillNulls { b }.with { "empty" }
|
||||
val b: DataColumn<String> = df1.b
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf("a", "b", "c", "d")(1, 2, 3, 4)
|
||||
val grouped = df
|
||||
.group { a and b }.into("e")
|
||||
.group { e and c }.into("f")
|
||||
|
||||
grouped.flatten().compareSchemas(strict = true)
|
||||
val flattened = grouped.flatten { f.e }
|
||||
flattened.compareSchemas(strict = true)
|
||||
flattened.ungroup { f }.compareSchemas(strict = true)
|
||||
|
||||
grouped.flatten(keepParentNameForColumns = true) { f.e }.compareSchemas(strict = true)
|
||||
|
||||
grouped.flatten { f.e and f }.compareSchemas(strict = true)
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.time.temporal.ChronoUnit
|
||||
import java.time.temporal.Temporal
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
interface ActivePlayer {
|
||||
val char: Int
|
||||
val timestamp: String
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalTypeInference::class)
|
||||
@OverloadResolutionByLambdaReturnType
|
||||
fun <T, V : Temporal> DataRow<T>.diff(unit: ChronoUnit, expression: RowExpression<T, V>): Long? = prev()?.let { p -> unit.between(expression(this, this), expression(p, p)) }
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val df = @DisableInterpretation DataFrame.readDelimStr("""
|
||||
char,level,race,charclass,zone,guild,timestamp
|
||||
59425,1,Orc,Rogue,Orgrimmar,165,01/01/08 00:02:04
|
||||
65494,9,Orc,Hunter,Durotar,-1,01/01/08 00:02:04
|
||||
""".trimIndent())
|
||||
val df1 = df.cast<ActivePlayer>()
|
||||
val format = DateTimeFormatter.ofPattern("MM/dd/yy HH:mm:ss")
|
||||
|
||||
val df2 = df1
|
||||
.convert { timestamp }.with { LocalDateTime.parse(it, format)!! }
|
||||
.add("tsDiff") { diff(ChronoUnit.MINUTES) { timestamp }?.let { it > 20 } ?: true }
|
||||
//.add("charDiff") { diff { char }?.let { it != 0 } ?: true }
|
||||
|
||||
df2.print()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
data class Record(val a: String, val b: Int)
|
||||
|
||||
fun box(): String {
|
||||
val df = listOf(Record("112", 42)).toDataFrame(maxDepth = 1)
|
||||
val df1 = df.group { a and b }.into("c")
|
||||
df1.c.a
|
||||
df1.c.b
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
data class Record(val a: String, val b: Int)
|
||||
|
||||
fun box(): String {
|
||||
val df = List(10) { Record(it.toString(), it) }.let { dataFrameOf(*it.toTypedArray()) }
|
||||
val df1 = df.groupBy { b }.aggregate { "123" into "fsdf" }
|
||||
|
||||
val nested = df.group { a and b }.into("c")
|
||||
val df2 = nested.groupBy { c.a }.aggregate { "123" into "ff" }
|
||||
df2.a
|
||||
|
||||
val df3 = nested.groupBy(moveToTop = false) { c.a }.aggregate { "123" into "ff" }
|
||||
df3.c.a
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.groupBy
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
enum class State {
|
||||
Idle,
|
||||
Productive,
|
||||
Maintenance,
|
||||
}
|
||||
|
||||
class Event(val toolId: String, val state: State, val timestamp: Long)
|
||||
|
||||
fun box(): String {
|
||||
val tool1 = "tool_1"
|
||||
val tool2 = "tool_2"
|
||||
val tool3 = "tool_3"
|
||||
|
||||
val events = listOf(
|
||||
Event(tool1, State.Idle, 0),
|
||||
Event(tool1, State.Productive, 5),
|
||||
Event(tool2, State.Idle, 0),
|
||||
Event(tool2, State.Maintenance, 10),
|
||||
Event(tool2, State.Idle, 20),
|
||||
Event(tool3, State.Idle, 0),
|
||||
Event(tool3, State.Productive, 25),
|
||||
).toDataFrame()
|
||||
|
||||
val lastTimestamp = events.maxOf { timestamp }
|
||||
val groupBy = events
|
||||
.groupBy { toolId }
|
||||
.sortBy { timestamp }
|
||||
.add("stateDuration") {
|
||||
(next()?.timestamp ?: lastTimestamp) - timestamp
|
||||
}.toDataFrame()
|
||||
|
||||
groupBy.group[0].stateDuration
|
||||
|
||||
groupBy.compareSchemas(strict = true)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
data class Record(val a: String, val b: Int)
|
||||
|
||||
fun box(): String {
|
||||
val df = List(10) { Record(it.toString(), it) }.let { dataFrameOf(*it.toTypedArray()) }
|
||||
val df1 = df.groupBy { b }.aggregate { sumFor { b } into "sum" }
|
||||
df1.sum.b
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf("a")(1, 1, 2, 3, 3).groupBy { a }.count()
|
||||
val i: Int = df.count[0]
|
||||
|
||||
val df1 = dataFrameOf("a")(1, 1, 2, 3, 3).groupBy { a }.count { a > 1 }
|
||||
val i1: Int = df1.count[0]
|
||||
|
||||
val df2 = dataFrameOf("a")(1, 1, 2, 3, 3).groupBy { a }.count("myCol") { a > 1 }
|
||||
val i2: Int = df2.myCol[0]
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf("a", "b", "c")(1, 2, 3)
|
||||
|
||||
val groupBy = df.groupBy { a }
|
||||
|
||||
val df1 = groupBy.updateGroups { it.remove { a } }.toDataFrame()
|
||||
df1.compileTimeSchema().print()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
// multiple columns
|
||||
val personsDf = dataFrameOf("name", "age", "city", "weight", "height", "yearsToRetirement")(
|
||||
"Alice", 15, "London", 99.5, "1.85", 50,
|
||||
"Bob", 20, "Paris", 140.0, "1.35", 45,
|
||||
"Charlie", 100, "Dubai", 75.0, "1.95", 0,
|
||||
"Rose", 1, "Moscow", 45.33, "0.79", 64,
|
||||
"Dylan", 35, "London", 23.4, "1.83", 30,
|
||||
"Eve", 40, "Paris", 56.72, "1.85", 25,
|
||||
"Frank", 55, "Dubai", 78.9, "1.35", 10,
|
||||
"Grace", 29, "Moscow", 67.8, "1.65", 36,
|
||||
"Hank", 60, "Paris", 80.22, "1.75", 5,
|
||||
"Isla", 22, "London", 75.1, "1.85", 43,
|
||||
)
|
||||
|
||||
// scenario #0: all numerical columns
|
||||
val res0 = personsDf.groupBy { city }.max()
|
||||
val max01: Int? = res0.age[0]
|
||||
val max02: Double? = res0.weight[0]
|
||||
res0.compareSchemas()
|
||||
|
||||
|
||||
// scenario #1: particular column
|
||||
val res1 = personsDf.groupBy { city }.maxFor { age }
|
||||
val max11: Int? = res1.age[0]
|
||||
res1.compareSchemas()
|
||||
|
||||
// scenario #1.1: particular column via max
|
||||
val res11 = personsDf.groupBy { city }.max { age }
|
||||
val max111: Int? = res11.age[0]
|
||||
res11.compareSchemas()
|
||||
|
||||
// scenario #2: particular column with new name - schema changes
|
||||
// TODO: not supported scenario
|
||||
// val res2 = personsDf.groupBy { city }.max("age", name = "newAge")
|
||||
// val max21: Int? = res2.newAge[0]
|
||||
|
||||
// scenario #2.1: particular column with new name - schema changes but via columnSelector
|
||||
val res21 = personsDf.groupBy { city }.max("newAge") { age }
|
||||
val max211: Int? = res21.newAge[0]
|
||||
res21.compareSchemas()
|
||||
|
||||
// scenario #2.2: two columns with new name - schema changes but via columnSelector
|
||||
// TODO: handle multiple columns https://github.com/Kotlin/dataframe/issues/1090
|
||||
val res22 = personsDf.groupBy { city }.max("newAge") { age and yearsToRetirement }
|
||||
val max221: Int? = res22.newAge[0]
|
||||
res22.compareSchemas()
|
||||
|
||||
// scenario #3: create new column via expression
|
||||
val res3 = personsDf.groupBy { city }.maxOf("newAge") { age / 10 }
|
||||
val max3: Int? = res3.newAge[0]
|
||||
res3.compareSchemas()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf("a")(1, 1, 2, 3, 3).groupBy { a }.add("id") { index() }.maxOf { 123 }
|
||||
val df1 = dataFrameOf("a")(1, 1, 2, 3, 3).groupBy { a }.add("id") { index() }.minOf { 123 }
|
||||
|
||||
val max = df.max[0]
|
||||
val min = df1.min[0]
|
||||
|
||||
df.compareSchemas()
|
||||
df1.compareSchemas()
|
||||
|
||||
val df2 = dataFrameOf("a")(1, 1, 2, 3, 3).groupBy { a }.add("id") { index() }.maxOf("myMax") { 123 }
|
||||
val df3 = dataFrameOf("a")(1, 1, 2, 3, 3).groupBy { a }.add("id") { index() }.minOf("myMin") { 123 }
|
||||
|
||||
df2.myMax
|
||||
df3.myMin
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val personsDf = dataFrameOf(
|
||||
"name",
|
||||
"age",
|
||||
"city",
|
||||
"weight",
|
||||
"height",
|
||||
"yearsToRetirement",
|
||||
"workExperienceYears",
|
||||
"dependentsCount",
|
||||
"annualIncome"
|
||||
)(
|
||||
"Alice", 15, "London", 99.5, "1.85", 50, 0.toShort(), 0.toByte(), 0L,
|
||||
"Bob", 20, "Paris", 140.0, "1.35", 45, 2.toShort(), 0.toByte(), 12000L,
|
||||
"Charlie", 100, "Dubai", 75.0, "1.95", 0, 70.toShort(), 0.toByte(), 0L,
|
||||
"Rose", 1, "Moscow", 45.33, "0.79", 64, 0.toShort(), 2.toByte(), 0L,
|
||||
"Dylan", 35, "London", 23.4, "1.83", 30, 15.toShort(), 1.toByte(), 90000L,
|
||||
"Eve", 40, "Paris", 56.72, "1.85", 25, 18.toShort(), 3.toByte(), 125000L,
|
||||
"Frank", 55, "Dubai", 78.9, "1.35", 10, 35.toShort(), 2.toByte(), 145000L,
|
||||
"Grace", 29, "Moscow", 67.8, "1.65", 36, 5.toShort(), 1.toByte(), 70000L,
|
||||
"Hank", 60, "Paris", 80.22, "1.75", 5, 40.toShort(), 4.toByte(), 200000L,
|
||||
"Isla", 22, "London", 75.1, "1.85", 43, 1.toShort(), 0.toByte(), 30000L,
|
||||
)
|
||||
|
||||
// scenario #0: all numerical columns
|
||||
val res0 = personsDf.groupBy { city }.mean()
|
||||
res0.compareSchemas()
|
||||
val mean01: Double? = res0.age[0]
|
||||
val mean02: Double? = res0.weight[0]
|
||||
val mean03: Double? = res0.yearsToRetirement[0]
|
||||
val mean04: Double? = res0.workExperienceYears[0]
|
||||
val mean05: Double? = res0.dependentsCount[0]
|
||||
val mean06: Double? = res0.annualIncome[0]
|
||||
|
||||
// scenario #1: particular column
|
||||
val res1 = personsDf.groupBy { city }.meanFor { age }
|
||||
val mean11: Double? = res1.age[0]
|
||||
res1.compareSchemas()
|
||||
|
||||
// scenario #1.1: particular column via mean
|
||||
val res11 = personsDf.groupBy { city }.mean { age }
|
||||
val mean111: Double? = res11.age[0]
|
||||
res11.compareSchemas()
|
||||
|
||||
// scenario #2: particular column with new name - schema changes
|
||||
// TODO: not supported scenario
|
||||
// val res2 = personsDf.groupBy { city }.mean("age", name = "newAge")
|
||||
// val mean21: Double? = res2.newAge[0]
|
||||
|
||||
// scenario #2.1: particular column with new name - schema changes but via columnSelector
|
||||
val res21 = personsDf.groupBy { city }.mean("newAge") { age }
|
||||
val mean211: Double? = res21.newAge[0]
|
||||
res21.compareSchemas()
|
||||
|
||||
// scenario #2.2: two columns with new name - schema changes but via columnSelector
|
||||
// TODO: handle multiple columns https://github.com/Kotlin/dataframe/issues/1090
|
||||
val res22 = personsDf.groupBy { city }.mean("newAge") { age and yearsToRetirement }
|
||||
val mean221: Double? = res22.newAge[0]
|
||||
res22.compareSchemas()
|
||||
|
||||
// scenario #3: create new column via expression
|
||||
val res3 = personsDf.groupBy { city }.meanOf("newAge") { age * 10 }
|
||||
val mean3: Double? = res3.newAge[0]
|
||||
res3.compareSchemas()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val personsDf = dataFrameOf(
|
||||
"name",
|
||||
"age",
|
||||
"city",
|
||||
"weight",
|
||||
"height",
|
||||
"yearsToRetirement",
|
||||
"workExperienceYears",
|
||||
"dependentsCount",
|
||||
"annualIncome"
|
||||
)(
|
||||
"Alice", 15, "London", 99.5, "1.85", 50, 0.toShort(), 0.toByte(), 0L,
|
||||
"Bob", 20, "Paris", 140.0, "1.35", 45, 2.toShort(), 0.toByte(), 12000L,
|
||||
"Charlie", 100, "Dubai", 75.0, "1.95", 0, 70.toShort(), 0.toByte(), 0L,
|
||||
"Rose", 1, "Moscow", 45.33, "0.79", 64, 0.toShort(), 2.toByte(), 0L,
|
||||
"Dylan", 35, "London", 23.4, "1.83", 30, 15.toShort(), 1.toByte(), 90000L,
|
||||
"Eve", 40, "Paris", 56.72, "1.85", 25, 18.toShort(), 3.toByte(), 125000L,
|
||||
"Frank", 55, "Dubai", 78.9, "1.35", 10, 35.toShort(), 2.toByte(), 145000L,
|
||||
"Grace", 29, "Moscow", 67.8, "1.65", 36, 5.toShort(), 1.toByte(), 70000L,
|
||||
"Hank", 60, "Paris", 80.22, "1.75", 5, 40.toShort(), 4.toByte(), 200000L,
|
||||
"Isla", 22, "London", 75.1, "1.85", 43, 1.toShort(), 0.toByte(), 30000L,
|
||||
)
|
||||
|
||||
// scenario #0: all intraComparable columns
|
||||
val res0 = personsDf.groupBy { city }.median()
|
||||
res0.compareSchemas()
|
||||
|
||||
val median01: Double? = res0.age[0]
|
||||
val median02: Double? = res0.weight[0]
|
||||
val median03: String? = res0.height[0]
|
||||
|
||||
// scenario #1: particular column
|
||||
val res1 = personsDf.groupBy { city }.medianFor { age }
|
||||
res1.compareSchemas()
|
||||
|
||||
val median11: Double? = res1.age[0]
|
||||
|
||||
// scenario #1.1: particular column via median
|
||||
val res11 = personsDf.groupBy { city }.median { age }
|
||||
res11.compareSchemas()
|
||||
|
||||
val median111: Double? = res11.age[0]
|
||||
|
||||
// scenario #2: particular column with new name - schema changes
|
||||
// TODO: not supported scenario
|
||||
// val res2 = personsDf.groupBy { city }.median("age", name = "newAge")
|
||||
// val median21: Int? = res2.newAge[0]
|
||||
|
||||
// scenario #2.1: particular column with new name - schema changes but via columnSelector
|
||||
val res21 = personsDf.groupBy { city }.median("newAge") { age }
|
||||
res21.compareSchemas()
|
||||
|
||||
val median211: Double? = res21.newAge[0]
|
||||
|
||||
// scenario #2.2: two columns with new name - schema changes but via columnSelector
|
||||
// TODO: handle multiple columns https://github.com/Kotlin/dataframe/issues/1090
|
||||
val res22 = personsDf.groupBy { city }.median("newAge") { age and yearsToRetirement }
|
||||
res22.compareSchemas()
|
||||
|
||||
val median221: Double? = res22.newAge[0]
|
||||
|
||||
// scenario #3: create new column via expression
|
||||
val res3 = personsDf.groupBy { city }.medianOf("newAgeExpr") { age * 10 }
|
||||
res3.compareSchemas()
|
||||
|
||||
val median3: Double? = res3.newAgeExpr[0]
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val personsDf = dataFrameOf(
|
||||
"name",
|
||||
"age",
|
||||
"city",
|
||||
"weight",
|
||||
"height",
|
||||
"yearsToRetirement",
|
||||
"workExperienceYears",
|
||||
"dependentsCount",
|
||||
"annualIncome"
|
||||
)(
|
||||
"Alice", 15, "London", 99.5, "1.85", 50, 0.toShort(), 0.toByte(), 0L,
|
||||
"Bob", 20, "Paris", 140.0, "1.35", 45, 2.toShort(), 0.toByte(), 12000L,
|
||||
"Charlie", 100, "Dubai", 75.0, "1.95", 0, 70.toShort(), 0.toByte(), 0L,
|
||||
"Rose", 1, "Moscow", 45.33, "0.79", 64, 0.toShort(), 2.toByte(), 0L,
|
||||
"Dylan", 35, "London", 23.4, "1.83", 30, 15.toShort(), 1.toByte(), 90000L,
|
||||
"Eve", 40, "Paris", 56.72, "1.85", 25, 18.toShort(), 3.toByte(), 125000L,
|
||||
"Frank", 55, "Dubai", 78.9, "1.35", 10, 35.toShort(), 2.toByte(), 145000L,
|
||||
"Grace", 29, "Moscow", 67.8, "1.65", 36, 5.toShort(), 1.toByte(), 70000L,
|
||||
"Hank", 60, "Paris", 80.22, "1.75", 5, 40.toShort(), 4.toByte(), 200000L,
|
||||
"Isla", 22, "London", 75.1, "1.85", 43, 1.toShort(), 0.toByte(), 30000L,
|
||||
)
|
||||
|
||||
// scenario #0: all numerical columns
|
||||
val res0 = personsDf.groupBy { city }.min()
|
||||
res0.compareSchemas()
|
||||
|
||||
val min01: Int? = res0.age[0]
|
||||
val min02: Double? = res0.weight[0]
|
||||
val min03: Int? = res0.yearsToRetirement[0]
|
||||
val min04: Short? = res0.workExperienceYears[0]
|
||||
val min05: Byte? = res0.dependentsCount[0]
|
||||
val min06: Long? = res0.annualIncome[0]
|
||||
val min07: String? = res0.name[0]
|
||||
val min08: String? = res0.city[0]
|
||||
val min09: String? = res0.height[0]
|
||||
|
||||
// scenario #1: particular column
|
||||
val res1 = personsDf.groupBy { city }.minFor { age }
|
||||
val min11: Int? = res1.age[0]
|
||||
res1.compareSchemas()
|
||||
|
||||
// scenario #1.1: particular column via min
|
||||
val res11 = personsDf.groupBy { city }.min { dependentsCount }
|
||||
val min111: Byte? = res11.dependentsCount[0]
|
||||
res11.compareSchemas()
|
||||
|
||||
// scenario #2: particular column with new name - schema changes
|
||||
// TODO: not supported scenario
|
||||
// val res2 = personsDf.groupBy { city }.min("age", name = "newAge")
|
||||
// val min21: Int? = res2.newAge[0]
|
||||
|
||||
// scenario #2.1: particular column with new name - schema changes but via columnSelector
|
||||
val res21 = personsDf.groupBy { city }.min("newName") { name }
|
||||
val min211: String? = res21.newName[0]
|
||||
res21.compareSchemas()
|
||||
|
||||
// scenario #2.2: two columns with new name - schema changes but via columnSelector
|
||||
// TODO: handle multiple columns https://github.com/Kotlin/dataframe/issues/1090
|
||||
val res22 = personsDf.groupBy { city }.min("newAge") { age and yearsToRetirement }
|
||||
val min221: Int? = res22.newAge[0]
|
||||
res22.compareSchemas()
|
||||
|
||||
// scenario #3: create new column via expression
|
||||
val res3 = personsDf.groupBy { city }.minOf("newAnnualIncome") { annualIncome / 2 }
|
||||
val min3: Long? = res3.newAnnualIncome[0]
|
||||
res3.compareSchemas()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf("a", "b", "c")(1,2,3)
|
||||
val df1 = df.groupBy { a }
|
||||
df1.keys.compareSchemas(strict = true)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
// multiple columns
|
||||
val personsDf = dataFrameOf("name", "age", "city", "weight", "height", "yearsToRetirement")(
|
||||
"Alice", 15, "London", 99.5, "1.85", 50,
|
||||
"Bob", 20, "Paris", 140.0, "1.35", 45,
|
||||
"Charlie", 100, "Dubai", 75.0, "1.95", 0,
|
||||
"Rose", 1, "Moscow", 45.33, "0.79", 64,
|
||||
"Dylan", 35, "London", 23.4, "1.83", 30,
|
||||
"Eve", 40, "Paris", 56.72, "1.85", 25,
|
||||
"Frank", 55, "Dubai", 78.9, "1.35", 10,
|
||||
"Grace", 29, "Moscow", 67.8, "1.65", 36,
|
||||
"Hank", 60, "Paris", 80.22, "1.75", 5,
|
||||
"Isla", 22, "London", 75.1, "1.85", 43,
|
||||
)
|
||||
|
||||
// scenario #0: all numerical columns
|
||||
val res0 = personsDf.groupBy { city }.std()
|
||||
val std01: Double? = res0.age[0]
|
||||
val std02: Double? = res0.weight[0]
|
||||
res0.compareSchemas()
|
||||
|
||||
// scenario #1: particular column
|
||||
val res1 = personsDf.groupBy { city }.stdFor { age }
|
||||
val std11: Double? = res1.age[0]
|
||||
res1.compareSchemas()
|
||||
|
||||
// scenario #1.1: particular column via std
|
||||
val res11 = personsDf.groupBy { city }.std { age }
|
||||
val std111: Double? = res11.age[0]
|
||||
res11.compareSchemas()
|
||||
|
||||
// scenario #2: particular column with new name - schema changes
|
||||
// TODO: not supported scenario
|
||||
// val res2 = personsDf.groupBy { city }.std("age", name = "newAge")
|
||||
// val std21: Double? = res2.newAge[0]
|
||||
|
||||
// scenario #2.1: particular column with new name - schema changes but via columnSelector
|
||||
val res21 = personsDf.groupBy { city }.std("newAge") { age }
|
||||
val std211: Double? = res21.newAge[0]
|
||||
res21.compareSchemas()
|
||||
|
||||
// scenario #2.2: two columns with new name - schema changes but via columnSelector
|
||||
// TODO: handle multiple columns https://github.com/Kotlin/dataframe/issues/1090
|
||||
val res22 = personsDf.groupBy { city }.std("newAge") { age and yearsToRetirement }
|
||||
val std221: Double? = res22.newAge[0]
|
||||
res22.compareSchemas()
|
||||
|
||||
// scenario #3: create new column via expression
|
||||
val res3 = personsDf.groupBy { city }.stdOf("newAge") { age * 10 }
|
||||
val std3: Double? = res3.newAge[0]
|
||||
res3.compareSchemas()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val personsDf = dataFrameOf(
|
||||
"name",
|
||||
"age",
|
||||
"city",
|
||||
"weight",
|
||||
"height",
|
||||
"yearsToRetirement",
|
||||
"workExperienceYears",
|
||||
"dependentsCount",
|
||||
"annualIncome"
|
||||
)(
|
||||
"Alice", 15, "London", 99.5, "1.85", 50, 0.toShort(), 0.toByte(), 0L,
|
||||
"Bob", 20, "Paris", 140.0, "1.35", 45, 2.toShort(), 0.toByte(), 12000L,
|
||||
"Charlie", 100, "Dubai", 75.0, "1.95", 0, 70.toShort(), 0.toByte(), 0L,
|
||||
"Rose", 1, "Moscow", 45.33, "0.79", 64, 0.toShort(), 2.toByte(), 0L,
|
||||
"Dylan", 35, "London", 23.4, "1.83", 30, 15.toShort(), 1.toByte(), 90000L,
|
||||
"Eve", 40, "Paris", 56.72, "1.85", 25, 18.toShort(), 3.toByte(), 125000L,
|
||||
"Frank", 55, "Dubai", 78.9, "1.35", 10, 35.toShort(), 2.toByte(), 145000L,
|
||||
"Grace", 29, "Moscow", 67.8, "1.65", 36, 5.toShort(), 1.toByte(), 70000L,
|
||||
"Hank", 60, "Paris", 80.22, "1.75", 5, 40.toShort(), 4.toByte(), 200000L,
|
||||
"Isla", 22, "London", 75.1, "1.85", 43, 1.toShort(), 0.toByte(), 30000L,
|
||||
)
|
||||
|
||||
// scenario #0: all numerical columns
|
||||
val res0 = personsDf.groupBy { city }.sum()
|
||||
res0.compareSchemas()
|
||||
|
||||
val sum01: Int? = res0.age[0]
|
||||
val sum02: Double? = res0.weight[0]
|
||||
val sum03: Int? = res0.yearsToRetirement[0]
|
||||
val sum04: Int? = res0.workExperienceYears[0]
|
||||
val sum05: Int? = res0.dependentsCount[0]
|
||||
val sum06: Long? = res0.annualIncome[0]
|
||||
|
||||
// scenario #1: particular column
|
||||
val res1 = personsDf.groupBy { city }.sumFor { annualIncome }
|
||||
val sum11: Long? = res1.annualIncome[0]
|
||||
res1.compareSchemas()
|
||||
|
||||
// scenario #1.1: particular column via sum
|
||||
val res11 = personsDf.groupBy { city }.sum { weight }
|
||||
val sum111: Double? = res11.weight[0]
|
||||
res11.compareSchemas()
|
||||
|
||||
// scenario #2: particular column with new name - schema changes
|
||||
// TODO: not supported scenario for String API
|
||||
// val res2 = personsDf.groupBy { city }.sum("age", name = "newAge")
|
||||
// val sum21: Int? = res2.newAge[0]
|
||||
|
||||
// scenario #2.1: particular column with new name - schema changes but via columnSelector
|
||||
val res21 = personsDf.groupBy { city }.sum("newAnnualIncome") { annualIncome }
|
||||
val sum211: Long? = res21.newAnnualIncome[0]
|
||||
res21.compareSchemas()
|
||||
|
||||
// scenario #2.2: two columns with new name - schema changes but via columnSelector
|
||||
// TODO: handle multiple columns https://github.com/Kotlin/dataframe/issues/1090
|
||||
val res22 = personsDf.groupBy { city }.sum("newAge") { age and yearsToRetirement }
|
||||
val sum221: Int? = res22.newAge[0]
|
||||
res22.compareSchemas()
|
||||
|
||||
// scenario #3: create new column via expression
|
||||
val res3 = personsDf.groupBy { city }.sumOf("newAge") { age * 10 }
|
||||
val sum3: Int? = res3.newAge[0]
|
||||
|
||||
// scenario #3.1: create new column via expression on Double column
|
||||
val res31 = personsDf.groupBy { city }.sumOf("newAge") { weight * 10 }
|
||||
val sum31: Double? = res31.newAge[0]
|
||||
res31.compareSchemas()
|
||||
|
||||
val df = dataFrameOf("a")(1, 2, 3)
|
||||
val res41 = df.groupBy { a named "b" }.sum { a }
|
||||
res41.compareSchemas()
|
||||
|
||||
val sum41: Int = res41.a[0]
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
data class Record(val a: String, val b: Int)
|
||||
|
||||
fun box(): String {
|
||||
val df = List(10) { Record(it.toString(), it) }.let { dataFrameOf(*it.toTypedArray()) }
|
||||
val df1 = df.groupBy { b }.toDataFrame()
|
||||
df1.group[0].a
|
||||
df1.group[0].b
|
||||
|
||||
val df2 = df.groupBy { b }.into("gr")
|
||||
df2.gr[0].a
|
||||
df2.gr[0].b
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf("a")(123)
|
||||
.add("b", infer = Infer.Nulls) { 123 }
|
||||
.convert { b }.with(infer = Infer.None) { it.toString() }
|
||||
.select { a and b and expr(infer = Infer.Nulls) { 42 } }
|
||||
|
||||
val b: String = df.b[0]
|
||||
val untitled: Int = df.untitled[0]
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
interface Cars {
|
||||
val year: Int
|
||||
}
|
||||
|
||||
fun `Name is evaluated to age`(df: DataFrame<Cars>) {
|
||||
val df1 = df.add("age") { 2022 - year }
|
||||
val col = df1.age
|
||||
}
|
||||
|
||||
fun `ReturnType is evaluated to Int`(df: DataFrame<Cars>) {
|
||||
val df1 = df.add("age") { 2022 - year }
|
||||
val col: DataColumn<Int> = df1.age
|
||||
}
|
||||
|
||||
fun box() = "OK"
|
||||
@@ -0,0 +1,15 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun `Dsl is evaluated to `(df: DataFrame<*>) {
|
||||
val df1 = df.add {
|
||||
"col1" from { 5 }
|
||||
expr { 5 } into "col2"
|
||||
}
|
||||
df1.col1
|
||||
df1.col2
|
||||
}
|
||||
|
||||
fun box() = "OK"
|
||||
@@ -0,0 +1,25 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
interface Person {
|
||||
val age: Int
|
||||
}
|
||||
|
||||
val df = dataFrameOf("age")(1).cast<Person>()
|
||||
|
||||
fun insert_properties() {
|
||||
val df1 = df.insert("year of birth") { 2021 - age }.under("test")
|
||||
df1.age
|
||||
df1.test.`year of birth`
|
||||
|
||||
val df2 = dataFrameOf("a")(11)
|
||||
.group { a }.into("group")
|
||||
.insert("b") { group.a * 111 }.under { group }
|
||||
df2.group.a
|
||||
df2.group.b
|
||||
}
|
||||
|
||||
fun box() = "OK"
|
||||
@@ -0,0 +1,12 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf("a", "b", "c")(1, 2, 3, 4, 5, 6)
|
||||
|
||||
val dfWithD = df.insert("d") { b * c }.after { a }
|
||||
|
||||
val dCol: DataColumn<Int> = dfWithD.d
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf("a", "b", "c")(1, 2, 3, 4, 5, 6)
|
||||
val grouped = df.group { a and b and c }.into("g")
|
||||
|
||||
val dfWithD = grouped.insert("d") { g.b * g.c }.after { g.b }
|
||||
|
||||
val dCol: DataColumn<Int> = dfWithD.g.d
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf("a", "b", "c")(1, 2, 3, 4, 5, 6)
|
||||
val dCol: DataColumn<String> = df.insert("d") { (b * c).toString() }.at(2)
|
||||
// weird way to check order, but ok?..
|
||||
.select { drop(2) }
|
||||
.select { take(1) }
|
||||
.select { d }.d
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf("versions")(mapOf("a" to 1)).convert { versions }.with { dataFrameOf(it.keys)(it.values) }
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df2 = dataFrameOf("id", "name", "preStage")(
|
||||
1, "11", null,
|
||||
2, "22", 1,
|
||||
3, "33", null,
|
||||
).group { id and name and preStage }.into("achievements")
|
||||
|
||||
val df3 = df2
|
||||
.filter { achievements.preStage != null }
|
||||
.join(df2) { achievements.preStage.match(right.achievements.id) }
|
||||
df3.achievements.name1
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val typed = dataFrameOf("name", "age", "city", "weight")(
|
||||
"Alice", 15, "London", 54,
|
||||
"Bob", 45, "Dubai", 87,
|
||||
"Charlie", 20, "Moscow", null,
|
||||
"Charlie", 40, "Milan", null,
|
||||
"Bob", 30, "Tokyo", 68,
|
||||
"Alice", 20, null, 55,
|
||||
"Charlie", 30, "Moscow", 90,
|
||||
)
|
||||
|
||||
val typed2 = dataFrameOf("name", "origin", "grade", "age")(
|
||||
"Alice", "London", 3, "young",
|
||||
"Alice", "London", 5, "old",
|
||||
"Bob", "Tokyo", 4, "young",
|
||||
"Bob", "Paris", 5, "old",
|
||||
"Charlie", "Moscow", 1, "young",
|
||||
"Charlie", "Moscow", 2, "old",
|
||||
"Bob", "Paris", 4, null,
|
||||
)
|
||||
|
||||
typed.join(typed2) { name and it.city.match(right.origin) }.assert()
|
||||
|
||||
typed.join(typed2, type = JoinType.Inner) { name and it.city.match(right.origin) }.assert()
|
||||
|
||||
typed.innerJoin(typed2) { name and it.city.match(right.origin) }.assert()
|
||||
|
||||
typed.leftJoin(typed2) { name and it.city.match(right.origin) }.assert()
|
||||
|
||||
typed.rightJoin(typed2) { name and it.city.match(right.origin) }.assert()
|
||||
|
||||
typed.fullJoin(typed2) { name and it.city.match(right.origin) }.assert()
|
||||
|
||||
typed.filterJoin(typed2) { city.match(right.origin) }.assert()
|
||||
|
||||
typed.excludeJoin(typed2) { city.match(right.origin) }.assert()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val typed = dataFrameOf("name", "age", "city", "weight")(
|
||||
"Alice", 15, "London", 54,
|
||||
"Bob", 45, "Dubai", 87,
|
||||
"Charlie", 20, "Moscow", null,
|
||||
"Charlie", 40, "Milan", null,
|
||||
"Bob", 30, "Tokyo", 68,
|
||||
"Alice", 20, null, 55,
|
||||
"Charlie", 30, "Moscow", 90,
|
||||
)
|
||||
|
||||
val typed2 = dataFrameOf("name", "origin", "grade", "age")(
|
||||
"Alice", "London", 3, "young",
|
||||
"Alice", "London", 5, "old",
|
||||
"Bob", "Tokyo", 4, "young",
|
||||
"Bob", "Paris", 5, "old",
|
||||
"Charlie", "Moscow", 1, "young",
|
||||
"Charlie", "Moscow", 2, "old",
|
||||
"Bob", "Paris", 4, null,
|
||||
)
|
||||
|
||||
typed.joinWith(typed2) { name == right.name && city == right.origin }.assert()
|
||||
|
||||
typed.joinWith(typed2, type = JoinType.Inner) { name == right.name && city == right.origin }.assert()
|
||||
|
||||
typed.innerJoinWith(typed2) { name == right.name && city == right.origin }.assert()
|
||||
|
||||
typed.leftJoinWith(typed2) { name == right.name && city == right.origin }.assert()
|
||||
|
||||
typed.rightJoinWith(typed2) { name == right.name && city == right.origin }.assert()
|
||||
|
||||
typed.fullJoinWith(typed2) { name == right.name && city == right.origin }.assert()
|
||||
|
||||
typed.filterJoinWith(typed2) { city == right.origin }.assert()
|
||||
|
||||
typed.excludeJoinWith(typed2) { city == right.origin }.assert()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val typed = dataFrameOf("name", "age", "city", "weight")(
|
||||
"Alice", 15, "London", 54,
|
||||
"Bob", 45, "Dubai", 87,
|
||||
"Charlie", 20, "Moscow", null,
|
||||
"Charlie", 40, "Milan", null,
|
||||
"Bob", 30, "Tokyo", 68,
|
||||
"Alice", 20, null, 55,
|
||||
"Charlie", 30, "Moscow", 90,
|
||||
)
|
||||
|
||||
val typed2 = dataFrameOf("name", "origin", "grade", "age")(
|
||||
"Alice", "London", 3, "young",
|
||||
"Alice", "London", 5, "old",
|
||||
"Bob", "Tokyo", 4, "young",
|
||||
"Bob", "Paris", 5, "old",
|
||||
"Charlie", "Moscow", 1, "young",
|
||||
"Charlie", "Moscow", 2, "old",
|
||||
"Bob", "Paris", 4, null,
|
||||
)
|
||||
|
||||
val joinWithGroups = typed.group { name and age }.into("gr")
|
||||
.innerJoinWith(typed2.group { origin and age }.into("gr")) { gr.name == right.name }
|
||||
|
||||
// columns from right are duplicated, including groups
|
||||
joinWithGroups.gr1.age
|
||||
|
||||
println(joinWithGroups.schema())
|
||||
joinWithGroups.assert()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
@DataSchema
|
||||
data class Sessions(
|
||||
val roomId: Int
|
||||
)
|
||||
|
||||
@DataSchema
|
||||
data class Rooms(
|
||||
val id: Int,
|
||||
val sort: Int,
|
||||
val name: String,
|
||||
)
|
||||
|
||||
fun box(): String {
|
||||
val rooms = dataFrameOf(Rooms(1, 2, "n"))
|
||||
val sessions = dataFrameOf(Sessions(1))
|
||||
|
||||
val df = sessions.join(rooms.group { id and name and sort }.into("room")) { roomId.match(right.room.id) }
|
||||
df.roomId
|
||||
df.room.sort
|
||||
df.room.name
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val typed = dataFrameOf("name", "age", "city", "weight")(
|
||||
"Alice", 15, "London", 54,
|
||||
"Bob", 45, "Dubai", 87,
|
||||
"Charlie", 20, "Moscow", null,
|
||||
"Charlie", 40, "Milan", null,
|
||||
"Bob", 30, "Tokyo", 68,
|
||||
"Alice", 20, null, 55,
|
||||
"Charlie", 30, "Moscow", 90,
|
||||
)
|
||||
|
||||
val typed2 = dataFrameOf("name", "origin", "grade", "age")(
|
||||
"Alice", "London", 3, "young",
|
||||
"Alice", "London", 5, "old",
|
||||
"Bob", "Tokyo", 4, "young",
|
||||
"Bob", "Paris", 5, "old",
|
||||
"Charlie", "Moscow", 1, "young",
|
||||
"Charlie", "Moscow", 2, "old",
|
||||
"Bob", "Paris", 4, null,
|
||||
)
|
||||
|
||||
val add2 = typed.group { name and age }.into("gr").add {
|
||||
"gr1" {
|
||||
"gr2" {
|
||||
"i" from { index() }
|
||||
}
|
||||
}
|
||||
}
|
||||
val add3 = typed2.group { origin and age }.into("gr").add {
|
||||
"gr1" {
|
||||
"gr2" {
|
||||
"i" from { index() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val joinWithGroups2 = add2.innerJoin(add3) { gr1.match(gr1) }
|
||||
|
||||
joinWithGroups2.assert()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val typed = dataFrameOf("name", "age", "city", "weight")(
|
||||
"Alice", 15, "London", 54,
|
||||
"Bob", 45, "Dubai", 87,
|
||||
"Charlie", 20, "Moscow", null,
|
||||
"Charlie", 40, "Milan", null,
|
||||
"Bob", 30, "Tokyo", 68,
|
||||
"Alice", 20, null, 55,
|
||||
"Charlie", 30, "Moscow", 90,
|
||||
)
|
||||
|
||||
val typed2 = dataFrameOf("name", "origin", "grade", "age")(
|
||||
"Alice", "London", 3, "young",
|
||||
"Alice", "London", 5, "old",
|
||||
"Bob", "Tokyo", 4, "young",
|
||||
"Bob", "Paris", 5, "old",
|
||||
"Charlie", "Moscow", 1, "young",
|
||||
"Charlie", "Moscow", 2, "old",
|
||||
"Bob", "Paris", 4, null,
|
||||
)
|
||||
|
||||
val joinWithGroups = typed.group { name and age }.into("gr")
|
||||
.innerJoin(typed2.group { origin and age }.into("gr")) { gr.name.match(right.name) }
|
||||
|
||||
println(joinWithGroups.schema())
|
||||
joinWithGroups.assert()
|
||||
|
||||
|
||||
val add = typed.group { name and age }.into("gr").add {
|
||||
"gr1" {
|
||||
"gr2" {
|
||||
"i" from { index() }
|
||||
}
|
||||
}
|
||||
}
|
||||
val add1 = typed2.group { origin and age }.into("gr").add {
|
||||
"gr1" {
|
||||
"gr2" {
|
||||
"a" from { "abc" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val joinWithGroups1 = add.innerJoin(add1) { gr.name.match(right.name) }
|
||||
|
||||
println(joinWithGroups1.schema())
|
||||
joinWithGroups1.assert()
|
||||
|
||||
val add2 = typed.group { name and age }.into("gr").add {
|
||||
"gr1" {
|
||||
"gr2" {
|
||||
"i" from { index() }
|
||||
}
|
||||
}
|
||||
}
|
||||
val add3 = typed2.group { origin and age }.into("gr").add {
|
||||
"gr1" {
|
||||
"gr2" {
|
||||
"i" from { index() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val joinWithGroups2 = add2.innerJoin(add3) { gr1.match(gr1) }
|
||||
joinWithGroups2.assert()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
public val df1 = dataFrameOf("a")(1).add("b") { 2 }
|
||||
internal val df2 = dataFrameOf("a")(1).add("b") { 2 }
|
||||
private val df3 = dataFrameOf("a")(1).add("b") { 2 }
|
||||
|
||||
class Container {
|
||||
public val df1 = dataFrameOf("a")(1).add("b") { 2 }
|
||||
internal val df2 = dataFrameOf("a")(1).add("b") { 2 }
|
||||
protected val df3 = dataFrameOf("a")(1).add("b") { 2 }
|
||||
private val df4 = dataFrameOf("a")(1).add("b") { 2 }
|
||||
}
|
||||
|
||||
fun box(): String = "OK"
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
interface Cars
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf("a")(1).cast<Cars>()
|
||||
val df1 = df.add("age") { 2022 }
|
||||
val col = df1.age
|
||||
return if (col[0] == 2022) "OK" else col[0].toString()
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = DataFrame.readCSV("https://raw.githubusercontent.com/Kotlin/dataframe/master/data/jetbrains_repositories.csv")
|
||||
|
||||
df.stargazers_count.print()
|
||||
|
||||
df.filter { stargazers_count > 50 }.print()
|
||||
|
||||
df.add("hello") { 42 }.hello
|
||||
|
||||
df
|
||||
.add("hello") { 42 }
|
||||
.add("hello1") { hello + 3}
|
||||
|
||||
df.sortByDesc { stargazers_count }.print(rowsLimit = 10)
|
||||
println(df.count { stargazers_count > 50 })
|
||||
println(df.count { stargazers_count == 0 })
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val df = dataFrameOf("a")(1).mapToFrame {
|
||||
"id" from { it }
|
||||
"group" {
|
||||
"a" from { it }
|
||||
}
|
||||
}
|
||||
|
||||
df.id
|
||||
df.group.a
|
||||
|
||||
df.compareSchemas(strict = true)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
// multiple columns
|
||||
val personsDf = dataFrameOf(
|
||||
"name",
|
||||
"age",
|
||||
"city",
|
||||
"weight",
|
||||
"height",
|
||||
"yearsToRetirement",
|
||||
"workExperienceYears",
|
||||
"dependentsCount",
|
||||
"annualIncome"
|
||||
)(
|
||||
"Alice", 15, "London", 99.5, "1.85", 50, 0.toShort(), 0.toByte(), 0L,
|
||||
"Bob", 20, "Paris", 140.0, "1.35", 45, 2.toShort(), 0.toByte(), 12000L,
|
||||
"Charlie", 100, "Dubai", 75.0, "1.95", 0, 70.toShort(), 0.toByte(), 0L,
|
||||
"Rose", 1, "Moscow", 45.33, "0.79", 64, 0.toShort(), 2.toByte(), 0L,
|
||||
"Dylan", 35, "London", 23.4, "1.83", 30, 15.toShort(), 1.toByte(), 90000L,
|
||||
"Eve", 40, "Paris", 56.72, "1.85", 25, 18.toShort(), 3.toByte(), 125000L,
|
||||
"Frank", 55, "Dubai", 78.9, "1.35", 10, 35.toShort(), 2.toByte(), 145000L,
|
||||
"Grace", 29, "Moscow", 67.8, "1.65", 36, 5.toShort(), 1.toByte(), 70000L,
|
||||
"Hank", 60, "Paris", 80.22, "1.75", 5, 40.toShort(), 4.toByte(), 200000L,
|
||||
"Isla", 22, "London", 75.1, "1.85", 43, 1.toShort(), 0.toByte(), 30000L,
|
||||
)
|
||||
|
||||
// scenario #0: all numerical columns
|
||||
val res0 = personsDf.max()
|
||||
res0.df().compareSchemas()
|
||||
|
||||
val max01: Int? = res0.age
|
||||
val max02: Double? = res0.weight
|
||||
val max03: Int? = res0.yearsToRetirement
|
||||
val max04: Short? = res0.workExperienceYears
|
||||
val max05: Byte? = res0.dependentsCount
|
||||
val max06: Long? = res0.annualIncome
|
||||
val max07: String? = res0.name
|
||||
val max08: String? = res0.city
|
||||
val max09: String? = res0.height
|
||||
|
||||
// scenario #1: particular column
|
||||
val res1 = personsDf.maxFor { age }
|
||||
res1.df().compareSchemas()
|
||||
|
||||
val max11: Int? = res1.age
|
||||
|
||||
// scenario #1.1: particular column with converted type
|
||||
val res11 = personsDf.maxFor { dependentsCount }
|
||||
res11.df().compareSchemas()
|
||||
|
||||
val max111: Byte? = res11.dependentsCount
|
||||
|
||||
// scenario #2: max of values per columns separately
|
||||
val res3 = personsDf.maxFor<_, String> { name and weight and workExperienceYears and dependentsCount and annualIncome }
|
||||
res3.df().compareSchemas()
|
||||
|
||||
val max31: String? = res3.name
|
||||
val max32: Double? = res3.weight
|
||||
val max33: Short? = res3.workExperienceYears
|
||||
val max34: Byte? = res3.dependentsCount
|
||||
val max35: Long? = res3.annualIncome
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
// multiple columns
|
||||
val personsDf = dataFrameOf(
|
||||
"name",
|
||||
"age",
|
||||
"city",
|
||||
"weight",
|
||||
"height",
|
||||
"yearsToRetirement",
|
||||
"workExperienceYears",
|
||||
"dependentsCount",
|
||||
"annualIncome"
|
||||
)(
|
||||
"Alice", 15, "London", 99.5, "1.85", 50, 0.toShort(), 0.toByte(), 0L,
|
||||
"Bob", 20, "Paris", 140.0, "1.35", 45, 2.toShort(), 0.toByte(), 12000L,
|
||||
"Charlie", 100, "Dubai", 75.0, "1.95", 0, 70.toShort(), 0.toByte(), 0L,
|
||||
"Rose", 1, "Moscow", 45.33, "0.79", 64, 0.toShort(), 2.toByte(), 0L,
|
||||
"Dylan", 35, "London", 23.4, "1.83", 30, 15.toShort(), 1.toByte(), 90000L,
|
||||
"Eve", 40, "Paris", 56.72, "1.85", 25, 18.toShort(), 3.toByte(), 125000L,
|
||||
"Frank", 55, "Dubai", 78.9, "1.35", 10, 35.toShort(), 2.toByte(), 145000L,
|
||||
"Grace", 29, "Moscow", 67.8, "1.65", 36, 5.toShort(), 1.toByte(), 70000L,
|
||||
"Hank", 60, "Paris", 80.22, "1.75", 5, 40.toShort(), 4.toByte(), 200000L,
|
||||
"Isla", 22, "London", 75.1, "1.85", 43, 1.toShort(), 0.toByte(), 30000L,
|
||||
)
|
||||
|
||||
// scenario #0: all numerical columns
|
||||
val res0 = personsDf.mean()
|
||||
res0.df().compareSchemas()
|
||||
|
||||
val mean01: Double? = res0.age
|
||||
val mean02: Double? = res0.weight
|
||||
val mean03: Double? = res0.yearsToRetirement
|
||||
val mean04: Double? = res0.workExperienceYears
|
||||
val mean05: Double? = res0.dependentsCount
|
||||
val mean06: Double? = res0.annualIncome
|
||||
|
||||
// scenario #1: particular column
|
||||
val res1 = personsDf.meanFor { age }
|
||||
res1.df().compareSchemas()
|
||||
|
||||
val mean11: Double? = res1.age
|
||||
|
||||
// scenario #1.1: particular column with converted type
|
||||
val res11 = personsDf.meanFor { dependentsCount }
|
||||
res11.df().compareSchemas()
|
||||
|
||||
val mean111: Double? = res11.dependentsCount
|
||||
|
||||
// scenario #2: mean of values per columns separately
|
||||
val res3 = personsDf.meanFor { age and weight and workExperienceYears and dependentsCount and annualIncome }
|
||||
res3.df().compareSchemas()
|
||||
|
||||
val mean31: Double? = res3.age
|
||||
val mean32: Double? = res3.weight
|
||||
val mean33: Double? = res3.workExperienceYears
|
||||
val mean34: Double? = res3.dependentsCount
|
||||
val mean35: Double? = res3.annualIncome
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
// multiple columns
|
||||
val personsDf = dataFrameOf(
|
||||
"name",
|
||||
"age",
|
||||
"city",
|
||||
"weight",
|
||||
"height",
|
||||
"yearsToRetirement",
|
||||
"workExperienceYears",
|
||||
"dependentsCount",
|
||||
"annualIncome"
|
||||
)(
|
||||
"Alice", 15, "London", 99.5, "1.85", 50, 0.toShort(), 0.toByte(), 0L,
|
||||
"Bob", 20, "Paris", 140.0, "1.35", 45, 2.toShort(), 0.toByte(), 12000L,
|
||||
"Charlie", 100, "Dubai", 75.0, "1.95", 0, 70.toShort(), 0.toByte(), 0L,
|
||||
"Rose", 1, "Moscow", 45.33, "0.79", 64, 0.toShort(), 2.toByte(), 0L,
|
||||
"Dylan", 35, "London", 23.4, "1.83", 30, 15.toShort(), 1.toByte(), 90000L,
|
||||
"Eve", 40, "Paris", 56.72, "1.85", 25, 18.toShort(), 3.toByte(), 125000L,
|
||||
"Frank", 55, "Dubai", 78.9, "1.35", 10, 35.toShort(), 2.toByte(), 145000L,
|
||||
"Grace", 29, "Moscow", 67.8, "1.65", 36, 5.toShort(), 1.toByte(), 70000L,
|
||||
"Hank", 60, "Paris", 80.22, "1.75", 5, 40.toShort(), 4.toByte(), 200000L,
|
||||
"Isla", 22, "London", 75.1, "1.85", 43, 1.toShort(), 0.toByte(), 30000L,
|
||||
)
|
||||
|
||||
// scenario #0: all numerical columns
|
||||
val res0 = personsDf.median()
|
||||
res0.df().compareSchemas()
|
||||
|
||||
val median01: Double? = res0.age
|
||||
val median02: Double? = res0.weight
|
||||
val median03: Double? = res0.yearsToRetirement
|
||||
val median04: Double? = res0.workExperienceYears
|
||||
val median05: Double? = res0.dependentsCount
|
||||
val median06: Double? = res0.annualIncome
|
||||
val median07: String? = res0.name
|
||||
val median08: String? = res0.city
|
||||
val median09: String? = res0.height
|
||||
|
||||
// scenario #1: particular column
|
||||
val res1 = personsDf.medianFor { age }
|
||||
res1.df().compareSchemas()
|
||||
|
||||
val median11: Double? = res1.age
|
||||
|
||||
// scenario #1.1: particular column with converted type
|
||||
val res11 = personsDf.medianFor { dependentsCount }
|
||||
res11.df().compareSchemas()
|
||||
|
||||
val median111: Double? = res11.dependentsCount
|
||||
|
||||
// scenario #2: median of values per columns separately
|
||||
val res3 = personsDf.medianFor<_, String> { name and weight and workExperienceYears and dependentsCount and annualIncome }
|
||||
res3.df().compareSchemas()
|
||||
|
||||
val median31: String? = res3.name
|
||||
val median32: Double? = res3.weight
|
||||
val median33: Double? = res3.workExperienceYears
|
||||
val median34: Double? = res3.dependentsCount
|
||||
val median35: Double? = res3.annualIncome
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
x
|
||||
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
val merge = dataFrameOf("a", "b")(1, null).merge { a and b }
|
||||
merge.into("b").compareSchemas(strict = true)
|
||||
merge.by { it }.into("b").compareSchemas(strict = true)
|
||||
merge.notNull().into("b").compareSchemas(strict = true)
|
||||
merge.notNull().by { it }.into("b").compareSchemas(strict = true)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
fun box(): String {
|
||||
// multiple columns
|
||||
val personsDf = dataFrameOf(
|
||||
"name",
|
||||
"age",
|
||||
"city",
|
||||
"weight",
|
||||
"height",
|
||||
"yearsToRetirement",
|
||||
"workExperienceYears",
|
||||
"dependentsCount",
|
||||
"annualIncome"
|
||||
)(
|
||||
"Alice", 15, "London", 99.5, "1.85", 50, 0.toShort(), 0.toByte(), 0L,
|
||||
"Bob", 20, "Paris", 140.0, "1.35", 45, 2.toShort(), 0.toByte(), 12000L,
|
||||
"Charlie", 100, "Dubai", 75.0, "1.95", 0, 70.toShort(), 0.toByte(), 0L,
|
||||
"Rose", 1, "Moscow", 45.33, "0.79", 64, 0.toShort(), 2.toByte(), 0L,
|
||||
"Dylan", 35, "London", 23.4, "1.83", 30, 15.toShort(), 1.toByte(), 90000L,
|
||||
"Eve", 40, "Paris", 56.72, "1.85", 25, 18.toShort(), 3.toByte(), 125000L,
|
||||
"Frank", 55, "Dubai", 78.9, "1.35", 10, 35.toShort(), 2.toByte(), 145000L,
|
||||
"Grace", 29, "Moscow", 67.8, "1.65", 36, 5.toShort(), 1.toByte(), 70000L,
|
||||
"Hank", 60, "Paris", 80.22, "1.75", 5, 40.toShort(), 4.toByte(), 200000L,
|
||||
"Isla", 22, "London", 75.1, "1.85", 43, 1.toShort(), 0.toByte(), 30000L,
|
||||
)
|
||||
|
||||
// scenario #0: all numerical columns
|
||||
val res0 = personsDf.min()
|
||||
res0.df().compareSchemas()
|
||||
|
||||
val min01: Int? = res0.age
|
||||
val min02: Double? = res0.weight
|
||||
val min03: Int? = res0.yearsToRetirement
|
||||
val min04: Short? = res0.workExperienceYears
|
||||
val min05: Byte? = res0.dependentsCount
|
||||
val min06: Long? = res0.annualIncome
|
||||
val min07: String? = res0.name
|
||||
val min08: String? = res0.city
|
||||
val min09: String? = res0.height
|
||||
|
||||
// scenario #1: particular column
|
||||
val res1 = personsDf.minFor { age }
|
||||
res1.df().compareSchemas()
|
||||
|
||||
val min11: Int? = res1.age
|
||||
|
||||
// scenario #1.1: particular column with converted type
|
||||
val res11 = personsDf.minFor { dependentsCount }
|
||||
res11.df().compareSchemas()
|
||||
|
||||
val min111: Byte? = res11.dependentsCount
|
||||
|
||||
// scenario #2: min of values per columns separately
|
||||
val res3 = personsDf.minFor<_, String> { name and weight and workExperienceYears and dependentsCount and annualIncome }
|
||||
res3.df().compareSchemas()
|
||||
|
||||
val min31: String? = res3.name
|
||||
val min32: Double? = res3.weight
|
||||
val min33: Short? = res3.workExperienceYears
|
||||
val min34: Byte? = res3.dependentsCount
|
||||
val min35: Long? = res3.annualIncome
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import org.jetbrains.kotlinx.dataframe.*
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.api.toDataFrame
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
data class Name(val firstName: String, val lastName: String)
|
||||
|
||||
data class Score(val subject: String, val value: Int)
|
||||
|
||||
data class Student(val name: Name, val age: Int, val scores: List<Score>)
|
||||
|
||||
fun box(): String {
|
||||
val students = listOf(
|
||||
Student(Name("Alice", "Cooper"), 15, listOf(Score("math", 4), Score("biology", 3))),
|
||||
Student(Name("Bob", "Marley"), 20, listOf(Score("music", 5))),
|
||||
)
|
||||
|
||||
val df = students.toDataFrame().groupBy { expr { name.firstName} }
|
||||
.aggregate {
|
||||
remove { age } into "a"
|
||||
}
|
||||
|
||||
df.compareSchemas(strict = true)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
FILE: moveAfter.kt
|
||||
public final fun box(): R|kotlin/String| {
|
||||
lval df: R|org/jetbrains/kotlinx/dataframe/DataFrame<<local>/Invoke_66>| = R|org/jetbrains/kotlinx/dataframe/api/dataFrameOf|(vararg(String(a), String(b), String(c))).R|kotlin/let|<R|org/jetbrains/kotlinx/dataframe/api/DataFrameBuilder|, R|org/jetbrains/kotlinx/dataframe/DataFrame<<local>/Invoke_64>|>(<L> = fun <anonymous>(it: R|org/jetbrains/kotlinx/dataframe/api/DataFrameBuilder|): R|org/jetbrains/kotlinx/dataframe/DataFrame<<local>/Invoke_64>| <inline=Inline, kind=EXACTLY_ONCE> {
|
||||
local abstract class Invoke_64I : R|kotlin/Any| {
|
||||
@R|org/jetbrains/kotlinx/dataframe/annotations/Order|(order = Int(2)) public abstract val c: R|kotlin/Int|
|
||||
public get(): R|kotlin/Int|
|
||||
|
||||
@R|org/jetbrains/kotlinx/dataframe/annotations/Order|(order = Int(1)) public abstract val b: R|kotlin/Int|
|
||||
public get(): R|kotlin/Int|
|
||||
|
||||
@R|org/jetbrains/kotlinx/dataframe/annotations/Order|(order = Int(0)) public abstract val a: R|kotlin/Int|
|
||||
public get(): R|kotlin/Int|
|
||||
|
||||
public constructor(): R|<local>/Invoke_64I|
|
||||
|
||||
}
|
||||
|
||||
local final class Scope0 : R|kotlin/Any| {
|
||||
public final val R|org/jetbrains/kotlinx/dataframe/DataRow<<local>/Invoke_64I>|.c: R|kotlin/Int|
|
||||
public get(): R|kotlin/Int|
|
||||
|
||||
public final val R|org/jetbrains/kotlinx/dataframe/ColumnsScope<<local>/Invoke_64I>|.c: R|org/jetbrains/kotlinx/dataframe/DataColumn<kotlin/Int>|
|
||||
public get(): R|org/jetbrains/kotlinx/dataframe/DataColumn<kotlin/Int>|
|
||||
|
||||
public final val R|org/jetbrains/kotlinx/dataframe/DataRow<<local>/Invoke_64I>|.b: R|kotlin/Int|
|
||||
public get(): R|kotlin/Int|
|
||||
|
||||
public final val R|org/jetbrains/kotlinx/dataframe/ColumnsScope<<local>/Invoke_64I>|.b: R|org/jetbrains/kotlinx/dataframe/DataColumn<kotlin/Int>|
|
||||
public get(): R|org/jetbrains/kotlinx/dataframe/DataColumn<kotlin/Int>|
|
||||
|
||||
public final val R|org/jetbrains/kotlinx/dataframe/DataRow<<local>/Invoke_64I>|.a: R|kotlin/Int|
|
||||
public get(): R|kotlin/Int|
|
||||
|
||||
public final val R|org/jetbrains/kotlinx/dataframe/ColumnsScope<<local>/Invoke_64I>|.a: R|org/jetbrains/kotlinx/dataframe/DataColumn<kotlin/Int>|
|
||||
public get(): R|org/jetbrains/kotlinx/dataframe/DataColumn<kotlin/Int>|
|
||||
|
||||
public constructor(): R|<local>/Scope0|
|
||||
|
||||
}
|
||||
|
||||
local abstract class Invoke_64 : R|<local>/Invoke_64I| {
|
||||
@R|org/jetbrains/kotlinx/dataframe/annotations/ScopeProperty|() public abstract val scope0: R|<local>/Scope0|
|
||||
public get(): R|<local>/Scope0|
|
||||
|
||||
public constructor(): R|<local>/Invoke_64|
|
||||
|
||||
}
|
||||
|
||||
^ R|<local>/it|.R|org/jetbrains/kotlinx/dataframe/api/DataFrameBuilder.invoke|(vararg(Int(1), Int(2), Int(3)))
|
||||
}
|
||||
).R|org/jetbrains/kotlinx/dataframe/api/move|<R|<local>/Invoke_64|, R|kotlin/Int|>(<L> = move@fun R|org/jetbrains/kotlinx/dataframe/api/ColumnsSelectionDsl<<local>/Invoke_64>|.<anonymous>(it: R|org/jetbrains/kotlinx/dataframe/api/ColumnsSelectionDsl<<local>/Invoke_64>|): R|org/jetbrains/kotlinx/dataframe/columns/ColumnsResolver<kotlin/Int>| <inline=NoInline> {
|
||||
^ (this@R|/box|, this@R|special/anonymous|).R|<local>/Scope0.a|
|
||||
}
|
||||
).R|kotlin/let|<R|org/jetbrains/kotlinx/dataframe/api/MoveClause<<local>/Invoke_64, kotlin/Int>|, R|org/jetbrains/kotlinx/dataframe/DataFrame<<local>/Invoke_66>|>(<L> = fun <anonymous>(it: R|org/jetbrains/kotlinx/dataframe/api/MoveClause<<local>/Invoke_64, kotlin/Int>|): R|org/jetbrains/kotlinx/dataframe/DataFrame<<local>/Invoke_66>| <inline=Inline, kind=EXACTLY_ONCE> {
|
||||
local abstract class Invoke_66I : R|kotlin/Any| {
|
||||
@R|org/jetbrains/kotlinx/dataframe/annotations/Order|(order = Int(2)) public abstract val c: R|kotlin/Int|
|
||||
public get(): R|kotlin/Int|
|
||||
|
||||
@R|org/jetbrains/kotlinx/dataframe/annotations/Order|(order = Int(0)) public abstract val b: R|kotlin/Int|
|
||||
public get(): R|kotlin/Int|
|
||||
|
||||
@R|org/jetbrains/kotlinx/dataframe/annotations/Order|(order = Int(1)) public abstract val a: R|kotlin/Int|
|
||||
public get(): R|kotlin/Int|
|
||||
|
||||
public constructor(): R|<local>/Invoke_66I|
|
||||
|
||||
}
|
||||
|
||||
local final class Scope0 : R|kotlin/Any| {
|
||||
public final val R|org/jetbrains/kotlinx/dataframe/DataRow<<local>/Invoke_66I>|.c: R|kotlin/Int|
|
||||
public get(): R|kotlin/Int|
|
||||
|
||||
public final val R|org/jetbrains/kotlinx/dataframe/ColumnsScope<<local>/Invoke_66I>|.c: R|org/jetbrains/kotlinx/dataframe/DataColumn<kotlin/Int>|
|
||||
public get(): R|org/jetbrains/kotlinx/dataframe/DataColumn<kotlin/Int>|
|
||||
|
||||
public final val R|org/jetbrains/kotlinx/dataframe/DataRow<<local>/Invoke_66I>|.b: R|kotlin/Int|
|
||||
public get(): R|kotlin/Int|
|
||||
|
||||
public final val R|org/jetbrains/kotlinx/dataframe/ColumnsScope<<local>/Invoke_66I>|.b: R|org/jetbrains/kotlinx/dataframe/DataColumn<kotlin/Int>|
|
||||
public get(): R|org/jetbrains/kotlinx/dataframe/DataColumn<kotlin/Int>|
|
||||
|
||||
public final val R|org/jetbrains/kotlinx/dataframe/DataRow<<local>/Invoke_66I>|.a: R|kotlin/Int|
|
||||
public get(): R|kotlin/Int|
|
||||
|
||||
public final val R|org/jetbrains/kotlinx/dataframe/ColumnsScope<<local>/Invoke_66I>|.a: R|org/jetbrains/kotlinx/dataframe/DataColumn<kotlin/Int>|
|
||||
public get(): R|org/jetbrains/kotlinx/dataframe/DataColumn<kotlin/Int>|
|
||||
|
||||
public constructor(): R|<local>/Scope0|
|
||||
|
||||
}
|
||||
|
||||
local abstract class Invoke_66 : R|<local>/Invoke_66I| {
|
||||
@R|org/jetbrains/kotlinx/dataframe/annotations/ScopeProperty|() public abstract val scope0: R|<local>/Scope0|
|
||||
public get(): R|<local>/Scope0|
|
||||
|
||||
public constructor(): R|<local>/Invoke_66|
|
||||
|
||||
}
|
||||
|
||||
^ R|<local>/it|.R|org/jetbrains/kotlinx/dataframe/api/after|<R|<local>/Invoke_64|, R|kotlin/Int|>(<L> = after@fun R|org/jetbrains/kotlinx/dataframe/api/ColumnsSelectionDsl<<local>/Invoke_64>|.<anonymous>(it: R|org/jetbrains/kotlinx/dataframe/api/ColumnsSelectionDsl<<local>/Invoke_64>|): R|org/jetbrains/kotlinx/dataframe/columns/SingleColumn<*>| <inline=NoInline> {
|
||||
^ (this@R|/box|, this@R|special/anonymous|).R|<local>/Scope0.b|
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
^box String(OK)
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user