Skip to content

Commit 7f96d6f

Browse files
committed
improving except api and writing tests
1 parent 681be27 commit 7f96d6f

File tree

7 files changed

+430
-560
lines changed

7 files changed

+430
-560
lines changed

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/allExcept.kt

Lines changed: 73 additions & 225 deletions
Large diffs are not rendered by default.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package org.jetbrains.kotlinx.dataframe
2+
3+
import org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDslTests
4+
import org.jetbrains.kotlinx.dataframe.api.select
5+
import org.jetbrains.kotlinx.dataframe.columns.ColumnSet
6+
import org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath
7+
import org.jetbrains.kotlinx.dataframe.columns.SingleColumn
8+
import org.jetbrains.kotlinx.dataframe.columns.asColumnSet
9+
import org.jetbrains.kotlinx.dataframe.impl.columns.allColumnsExceptKeepingStructure
10+
import org.jetbrains.kotlinx.dataframe.impl.columns.singleOrNullImpl
11+
import org.jetbrains.kotlinx.dataframe.impl.columns.transformSingleWithContext
12+
import org.jetbrains.kotlinx.dataframe.impl.columns.transformWithContext
13+
import org.jetbrains.kotlinx.dataframe.samples.api.firstName
14+
import org.jetbrains.kotlinx.dataframe.samples.api.name
15+
import org.jetbrains.kotlinx.dataframe.samples.api.secondName
16+
import org.junit.Test
17+
18+
class Experiments : ColumnsSelectionDslTests() {
19+
20+
@Test
21+
fun `TEMP experiments`() {
22+
dfGroup.select {
23+
@Suppress("UNCHECKED_CAST")
24+
fun ColumnSet<*>.containingGroups(): ColumnSet<DataRow<*>> = transformWithContext {
25+
it.mapNotNull {
26+
if (it.path.size > 1) {
27+
it.path.dropLast()
28+
.resolveSingle(this@transformWithContext) as ColumnWithPath<DataRow<*>>?
29+
} else {
30+
null
31+
}
32+
}
33+
}
34+
35+
fun SingleColumn<*>.containingGroup(): SingleColumn<DataRow<*>> =
36+
asColumnSet().containingGroups().singleOrNullImpl()
37+
38+
fun SingleColumn<*>.colsInSameColGroup(): ColumnSet<*> = transformSingleWithContext {
39+
val parent = containingGroup().resolveSingle(this)
40+
?: return@transformSingleWithContext emptyList()
41+
parent.cols().allColumnsExceptKeepingStructure(listOf(it))
42+
}
43+
44+
fun SingleColumn<*>.colGroupNoOthers(): SingleColumn<DataRow<*>> =
45+
containingGroup().asColumnSet()
46+
.except(colsInSameColGroup())
47+
.singleOrNullImpl()
48+
49+
fun SingleColumn<*>.colGroupsNoOthers(): ColumnSet<DataRow<*>> = transformSingleWithContext {
50+
buildList {
51+
var current = it
52+
while (true) {
53+
val parent = current.colGroupNoOthers()
54+
.resolveSingle(this@transformSingleWithContext)
55+
?: break
56+
add(parent)
57+
current = parent
58+
}
59+
}
60+
}
61+
62+
fun SingleColumn<*>.rootColGroupNoOthers(): SingleColumn<DataRow<*>> =
63+
colGroupsNoOthers().simplify().single()
64+
65+
fun SingleColumn<*>.colGroups(): ColumnSet<DataRow<*>> = transformSingleWithContext {
66+
buildList {
67+
var path = it.path
68+
while (path.size > 1) {
69+
path = path.dropLast(1)
70+
val parent = path
71+
.resolveSingle(this@transformSingleWithContext) as ColumnWithPath<DataRow<*>>?
72+
if (parent != null) add(parent)
73+
}
74+
}
75+
}
76+
77+
fun SingleColumn<*>.rootColGroup(): SingleColumn<DataRow<*>> =
78+
colGroups().simplify().single()
79+
80+
// colsAtAnyDepth { it.name == "secondName" }.single().parentNoSiblings().parentNoSiblings()
81+
// cols(name) except {
82+
// name {
83+
// firstName {
84+
// secondName and thirdName
85+
// } and lastName
86+
// }
87+
// }
88+
89+
// name.firstName.firstName.rootColGroup()
90+
91+
(name.firstName and name.firstName.secondName).simplify()
92+
}.alsoDebug()
93+
}
94+
}

0 commit comments

Comments
 (0)