/
DataFrameTableTest.kt
49 lines (38 loc) · 1.38 KB
/
DataFrameTableTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package space.kscience.dataforge.dataframe
import org.jetbrains.kotlinx.dataframe.api.add
import org.jetbrains.kotlinx.dataframe.api.column
import org.junit.jupiter.api.Test
import space.kscience.dataforge.misc.DFExperimental
import space.kscience.tables.*
import kotlin.math.pow
import kotlin.test.assertEquals
import kotlin.test.assertTrue
@OptIn(DFExperimental::class)
internal class DataFrameTableTest {
@Test
fun convertTableToDataFrame() {
val x by ColumnHeader.typed<Double>()
val x2 by ColumnHeader.typed<Double>()
val y by ColumnHeader.typed<Double>()
val table = ColumnTable<Double?>(100) {
//filling column with double values equal to index
fill(x) { it.toDouble() }
//virtual column filled with x^2
transform(x2) { it[x].pow(2) }
//Fixed column filled with x^2 + 1
column(y, x2.values.map { it?.plus(1) })
}
val dataFrame = table.toDataFrame()
//println( dataFrame)
val z by column<Double>()
val newFrame = dataFrame.add {
z.from { it[x] + it[y] + 1.0 }
}
//println(newFrame)
val newTable = newFrame.asTable()
assertEquals(newTable.columns[x], table.columns[x])
assertTrue {
table.rowsToColumn("z") { it[x] + it[y] + 1.0 }.contentEquals(newTable.columns["z"])
}
}
}