Skip to content

Commit 0b8943b

Browse files
committed
Move tests that use dataframe preprocessor
1 parent 9d637a8 commit 0b8943b

Some content is hidden

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

50 files changed

+220
-379
lines changed

src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/implode.kt

-21
This file was deleted.

src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/BaseTest.kt

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.jetbrains.kotlinx.dataframe.testSets.person
22

3+
import org.jetbrains.kotlinx.dataframe.ColumnsContainer
4+
import org.jetbrains.kotlinx.dataframe.DataColumn
35
import org.jetbrains.kotlinx.dataframe.DataFrame
6+
import org.jetbrains.kotlinx.dataframe.DataRow
47
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
58
import org.jetbrains.kotlinx.dataframe.api.cast
69
import org.jetbrains.kotlinx.dataframe.api.column
@@ -15,6 +18,15 @@ interface Person {
1518
val weight: Int?
1619
}
1720

21+
val DataRow<Person>.name: String get() = this["name"] as String
22+
val DataRow<Person>.age: Int get() = this["age"] as Int
23+
val DataRow<Person>.city: String? get() = this["city"] as String?
24+
val DataRow<Person>.weight: Int? get() = this["weight"] as Int?
25+
val ColumnsContainer<Person>.name: DataColumn<String> get() = this["name"] as DataColumn<String>
26+
val ColumnsContainer<Person>.age: DataColumn<Int> get() = this["age"] as DataColumn<Int>
27+
val ColumnsContainer<Person>.city: DataColumn<String?> get() = this["city"] as DataColumn<String?>
28+
val ColumnsContainer<Person>.weight: DataColumn<Int?> get() = this["weight"] as DataColumn<Int?>
29+
1830
open class BaseTest {
1931

2032
// Data set

src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/add.kt renamed to tests/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/add.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.jetbrains.kotlinx.dataframe.api
22

33
import io.kotest.matchers.shouldBe
4-
import org.jetbrains.kotlinx.dataframe.prev
54
import org.junit.Test
65

76
class AddTests {
@@ -10,7 +9,7 @@ class AddTests {
109
fun `add with new`() {
1110
val x by columnOf(7, 2, 0, 3, 4, 2, 5, 0, 3, 4)
1211
val df = dataFrameOf(x)
13-
val added = df.add("Y") { if (x() == 0) 0 else (prev?.new() ?: 0) + 1 }
12+
val added = df.add("Y") { if (x() == 0) 0 else (prev()?.new() ?: 0) + 1 }
1413
val expected = listOf(1, 2, 0, 1, 2, 3, 4, 0, 1, 2)
1514
added["Y"].values() shouldBe expected
1615
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.jetbrains.kotlinx.dataframe.api
22

33
import io.kotest.matchers.shouldBe
4-
import org.jetbrains.kotlinx.dataframe.nrow
54
import org.jetbrains.kotlinx.dataframe.size
65
import org.junit.Test
76

@@ -12,7 +11,7 @@ class ChunkedTests {
1211
val a by columnOf(listOf(1, 2, 3).toColumn("b"), listOf(4, 5, 6).toColumn("c"))
1312
val chunked = a.asColumnGroup().chunked(2)
1413
chunked.size shouldBe 2
15-
chunked.name shouldBe "a"
16-
chunked[1].nrow shouldBe 1
14+
chunked.name() shouldBe "a"
15+
chunked[1].rowsCount() shouldBe 1
1716
}
1817
}

src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/corr.kt renamed to tests/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/corr.kt

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package org.jetbrains.kotlinx.dataframe.api
33
import io.kotest.matchers.doubles.ToleranceMatcher
44
import io.kotest.matchers.should
55
import io.kotest.matchers.shouldBe
6-
import org.jetbrains.kotlinx.dataframe.ncol
7-
import org.jetbrains.kotlinx.dataframe.nrow
86
import org.junit.Test
97

108
class CorrTests {
@@ -17,8 +15,8 @@ class CorrTests {
1715
@Test
1816
fun `corr with boolean`() {
1917
val corr = df.corr("a", "b").with("c")
20-
corr.nrow shouldBe 2
21-
corr.ncol shouldBe 2
18+
corr.rowsCount() shouldBe 2
19+
corr.columnsCount() shouldBe 2
2220
corr.getColumn(0) shouldBe (columnOf("a", "b") named "column")
2321
corr.getColumn(1).name() shouldBe "c"
2422
corr["c"][0] as Double should ToleranceMatcher(1.0, 0.01)

src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/gather.kt renamed to tests/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/gather.kt

+5-7
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import org.jetbrains.kotlinx.dataframe.codeGen.generateCode
1010
import org.jetbrains.kotlinx.dataframe.columns.ColumnKind
1111
import org.jetbrains.kotlinx.dataframe.io.readJsonStr
1212
import org.jetbrains.kotlinx.dataframe.kind
13-
import org.jetbrains.kotlinx.dataframe.ncol
14-
import org.jetbrains.kotlinx.dataframe.nrow
1513
import org.junit.Test
1614
import kotlin.reflect.typeOf
1715

@@ -106,7 +104,7 @@ class GatherTests {
106104

107105
val newDf = listOf(
108106
name.withValues(List(cols.size) { name[0] }),
109-
mode.withValues(cols.map { it.name }),
107+
mode.withValues(cols.map { it.name() }),
110108
dataRows.map { it.getValueOrNull<String>("c1") }.toColumn("c1"),
111109
dataRows.map { it.getValueOrNull<String>("c2") }.toColumn("c2"),
112110
dataRows.map { it.getValueOrNull<String>("c3") }.toColumn("c3")
@@ -133,8 +131,8 @@ class GatherTests {
133131

134132
fun AnyFrame.check() {
135133
this["value"].kind shouldBe ColumnKind.Group
136-
ncol shouldBe 2
137-
nrow shouldBe 3
134+
columnsCount() shouldBe 2
135+
rowsCount() shouldBe 3
138136
}
139137

140138
df.gather { languages }.into("key", "value").check()
@@ -159,11 +157,11 @@ class GatherTests {
159157
val b by columnOf(3, 4)
160158

161159
var df = dataFrameOf(a, b).gather { a and b }.valuesInto("data")
162-
df.ncol shouldBe 1
160+
df.columnsCount() shouldBe 1
163161
df["data"].values() shouldBe listOf(1, 3, 2, 4)
164162

165163
df = dataFrameOf(a, b).gather { a and b }.where { it % 2 == 1 }.valuesInto("data")
166-
df.ncol shouldBe 1
164+
df.columnsCount() shouldBe 1
167165
df["data"].values() shouldBe listOf(1, 3)
168166
}
169167

src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/get.kt renamed to tests/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/get.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class GetTests {
1212

1313
@Test
1414
fun `exceptions from empty dataframe`() {
15-
val empty = DataFrame.Empty
15+
val empty = DataFrame.empty()
1616
shouldThrow<NoSuchElementException> {
1717
empty.first()
1818
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package org.jetbrains.kotlinx.dataframe.api
22

33
import io.kotest.matchers.shouldBe
4-
import org.jetbrains.kotlinx.dataframe.DataFrame
54
import org.junit.Test
65

76
class MapTests {
87

98
@Test
109
fun `map frame column with empty frames`() {
11-
val frames by columnOf(dataFrameOf("a")(1), DataFrame.Empty)
10+
val frames by columnOf(dataFrameOf("a")(1), emptyDataFrame())
1211
frames.map { it.firstOrNull() }.size() shouldBe frames.size()
1312
}
1413
}

src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/parse.kt renamed to tests/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/parse.kt

+9-11
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import org.jetbrains.kotlinx.dataframe.DataFrame
88
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
99
import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
1010
import org.jetbrains.kotlinx.dataframe.io.readJsonStr
11-
import org.jetbrains.kotlinx.dataframe.ncol
12-
import org.jetbrains.kotlinx.dataframe.nrow
1311
import org.jetbrains.kotlinx.dataframe.type
1412
import org.junit.Test
1513
import java.time.LocalTime
@@ -26,8 +24,8 @@ class ParseTests {
2624
]
2725
""".trimIndent()
2826
val df = DataFrame.readJsonStr(json)
29-
df.ncol shouldBe 3
30-
df.nrow shouldBe 2
27+
df.columnsCount() shouldBe 3
28+
df.rowsCount() shouldBe 2
3129
df["a"].type() shouldBe typeOf<Int>()
3230
df["b"].type() shouldBe typeOf<Comparable<*>>()
3331
df["c"].type() shouldBe typeOf<Double?>()
@@ -43,10 +41,10 @@ class ParseTests {
4341
""".trimIndent()
4442
val df = DataFrame.readJsonStr(json)
4543
println(df)
46-
df.ncol shouldBe 1
47-
df.nrow shouldBe 3
44+
df.columnsCount() shouldBe 1
45+
df.rowsCount() shouldBe 3
4846
val group = df["a"] as ColumnGroup<*>
49-
group.ncol shouldBe 3
47+
group.columnsCount() shouldBe 3
5048
group["b"].type() shouldBe typeOf<Int?>()
5149
group["value"].type() shouldBe typeOf<String?>()
5250
group["array"].type() shouldBe typeOf<List<Int>>()
@@ -61,8 +59,8 @@ class ParseTests {
6159
]
6260
""".trimIndent()
6361
val df = DataFrame.readJsonStr(json)
64-
df.ncol shouldBe 1
65-
df.nrow shouldBe 3
62+
df.columnsCount() shouldBe 1
63+
df.rowsCount() shouldBe 3
6664
df["a"].type() shouldBe typeOf<List<Number>>()
6765
df[1]["a"] shouldBe emptyList<Int>()
6866
}
@@ -75,8 +73,8 @@ class ParseTests {
7573
]
7674
""".trimIndent()
7775
val df = DataFrame.readJsonStr(json)
78-
df.ncol shouldBe 1
79-
df.nrow shouldBe 2
76+
df.columnsCount() shouldBe 1
77+
df.rowsCount() shouldBe 2
8078
println(df)
8179
val group = df["a"] as FrameColumn<*>
8280
}

src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/pivot.kt renamed to tests/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/pivot.kt

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package org.jetbrains.kotlinx.dataframe.api
22

33
import io.kotest.matchers.shouldBe
4-
import org.jetbrains.kotlinx.dataframe.ncol
5-
import org.jetbrains.kotlinx.dataframe.nrow
64
import org.junit.Test
75
import kotlin.reflect.typeOf
86

@@ -18,7 +16,7 @@ class PivotTests {
1816
fun `simple pivot`() {
1917
val pivoted = df.pivot(b, inward = false).groupBy(a).values(c)
2018
pivoted.columnNames() shouldBe listOf("a", "q", "w")
21-
pivoted.nrow shouldBe 2
19+
pivoted.rowsCount() shouldBe 2
2220
pivoted["q"].values() shouldBe listOf('x', 'y')
2321
pivoted["w"].values() shouldBe listOf(null, 'z')
2422
}
@@ -27,7 +25,7 @@ class PivotTests {
2725
fun `pivot with rename`() {
2826
val pivoted = df.pivot(b).groupBy(a).values { c default '?' into "d" and (c into "e") }
2927
pivoted.columnNames() shouldBe listOf("a", "b")
30-
pivoted.nrow shouldBe 2
28+
pivoted.rowsCount() shouldBe 2
3129

3230
pivoted["b"]["q"]["d"].values() shouldBe listOf('x', 'y')
3331
pivoted["b"]["q"]["e"].values() shouldBe listOf('x', 'y')
@@ -41,8 +39,8 @@ class PivotTests {
4139
get(c).first() default '-' into "first"
4240
get(c).last() into "last" default '?'
4341
}
44-
pivoted.ncol shouldBe 3
45-
pivoted.nrow shouldBe 2
42+
pivoted.columnsCount() shouldBe 3
43+
pivoted.rowsCount() shouldBe 2
4644
val cols = pivoted.getColumns { except(a).allDfs() }
4745
cols.size shouldBe 4
4846
cols.forEach {
@@ -127,7 +125,7 @@ class PivotTests {
127125
df.pivot("a").minBy("b").values("c", "d", separate = true) shouldBe
128126
dataFrameOf("c1", "c2", "d1", "d2")(
129127
2, 3, 4, 2
130-
).move { all() }.into { pathOf(it.name[0].toString(), it.name[1].toString()) }[0]
128+
).move { all() }.into { pathOf(it.name()[0].toString(), it.name()[1].toString()) }[0]
131129
}
132130

133131
@Test

src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/toDataFrame.kt renamed to tests/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/toDataFrame.kt

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package org.jetbrains.kotlinx.dataframe.api
33
import io.kotest.matchers.shouldBe
44
import org.jetbrains.kotlinx.dataframe.columns.ColumnKind
55
import org.jetbrains.kotlinx.dataframe.kind
6-
import org.jetbrains.kotlinx.dataframe.ncol
7-
import org.jetbrains.kotlinx.dataframe.nrow
86
import org.junit.Test
97
import kotlin.reflect.typeOf
108

@@ -30,8 +28,8 @@ class CreateDataFrameTests {
3028
}
3129

3230
val df = listOf(Data()).toDataFrame()
33-
df.ncol shouldBe 2
34-
df.nrow shouldBe 1
31+
df.columnsCount() shouldBe 2
32+
df.rowsCount() shouldBe 1
3533
df.columnTypes() shouldBe listOf(typeOf<IllegalStateException>(), typeOf<Int>())
3634
(df["a"][0] is IllegalStateException) shouldBe true
3735
df["b"][0] shouldBe 1

0 commit comments

Comments
 (0)