Skip to content

Commit 6ae692d

Browse files
committed
transform: (ColumnSet<*>) -> ColumnSet<*>
1 parent dac8c17 commit 6ae692d

30 files changed

+158
-168
lines changed

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/DataColumn.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ public interface DataColumn<out T> : BaseColumn<T> {
109109

110110
override fun resolveSingleAfter(
111111
context: ColumnResolutionContext,
112-
transform: (List<ColumnWithPath<*>>) -> List<ColumnWithPath<*>>,
113-
): ColumnWithPath<T>? = this
114-
.transform(transform)
115-
.let { it as DataColumn<T> }
116-
.addPath()
112+
transform: (ColumnSet<*>) -> ColumnSet<*>,
113+
): ColumnWithPath<T>? =
114+
transform(this).cast<T>()
115+
.let { it as DataColumn<T> }
116+
.addPath()
117117

118118
override operator fun getValue(thisRef: Any?, property: KProperty<*>): DataColumn<T> =
119119
super.getValue(thisRef, property) as DataColumn<T>

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/ColumnsSelectionDsl.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -734,9 +734,9 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
734734

735735
override fun resolveAfterTransform(
736736
context: ColumnResolutionContext,
737-
transform: (List<ColumnWithPath<Any?>>) -> List<ColumnWithPath<Any?>>,
737+
transform: (ColumnSet<*>) -> ColumnSet<*>,
738738
): List<ColumnWithPath<Any?>> =
739-
process(this@rangeTo.transform(transform) as AnyColumnReference, context)
739+
process(transform(this@rangeTo) as AnyColumnReference, context)
740740
}
741741

742742
/**
@@ -3972,14 +3972,15 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
39723972

39733973
public fun <C> ColumnSet<C>.recursively(includeGroups: Boolean = true): ColumnSet<C> = object : ColumnSet<C> {
39743974

3975-
private fun flatten(list: List<ColumnWithPath<*>>): List<ColumnWithPath<*>> =
3975+
private fun flatten(columnSet: ColumnSet<*>): ColumnSet<*> = columnSet.transform { list ->
39763976
list
39773977
.filter { it.isColumnGroup() } // TODO should I include this from dfs?
39783978
.flatMap {
39793979
it.children()
39803980
.dfs()
39813981
.filter { includeGroups || !it.isColumnGroup() }
39823982
}
3983+
}
39833984

39843985
override fun resolve(
39853986
context: ColumnResolutionContext,
@@ -3988,10 +3989,10 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
39883989

39893990
override fun resolveAfterTransform(
39903991
context: ColumnResolutionContext,
3991-
transform: (List<ColumnWithPath<*>>) -> List<ColumnWithPath<*>>,
3992-
): List<ColumnWithPath<C>> = this@recursively
3993-
.transform { transform(it) as List<ColumnWithPath<C>> }
3994-
.resolveAfterTransform(context = context, transform = ::flatten)
3992+
transform: (ColumnSet<*>) -> ColumnSet<*>,
3993+
): List<ColumnWithPath<C>> =
3994+
transform(this@recursively).cast<C>()
3995+
.resolveAfterTransform(context = context, transform = ::flatten)
39953996
}
39963997

39973998
public fun <C> ColumnSet<C>.rec(includeGroups: Boolean = true): ColumnSet<C> = recursively(includeGroups)

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/join.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public class ColumnMatch<C>(public val left: ColumnReference<C>, public val righ
111111

112112
override fun resolveAfterTransform(
113113
context: ColumnResolutionContext,
114-
transform: (List<ColumnWithPath<*>>) -> List<ColumnWithPath<*>>,
114+
transform: (ColumnSet<*>) -> ColumnSet<*>,
115115
): List<ColumnWithPath<C>> {
116116
throw UnsupportedOperationException()
117117
}

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/columns/ColumnReference.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.jetbrains.kotlinx.dataframe.columns
22

33
import org.jetbrains.kotlinx.dataframe.*
44
import org.jetbrains.kotlinx.dataframe.api.asColumnGroup
5+
import org.jetbrains.kotlinx.dataframe.api.cast
56
import org.jetbrains.kotlinx.dataframe.api.name
67
import org.jetbrains.kotlinx.dataframe.api.toDataFrame
78
import org.jetbrains.kotlinx.dataframe.impl.columnName
@@ -39,11 +40,9 @@ public interface ColumnReference<out C> : SingleColumn<C> {
3940

4041
override fun resolveSingleAfter(
4142
context: ColumnResolutionContext,
42-
transform: (List<ColumnWithPath<*>>) -> List<ColumnWithPath<*>>,
43+
transform: (ColumnSet<*>) -> ColumnSet<*>,
4344
): ColumnWithPath<C>? =
44-
context.df
45-
.asColumnGroup()
46-
.transform { transform(it as List<ColumnWithPath<C>>) }
45+
transform(context.df.asColumnGroup()).cast<C>()
4746
.resolve(context)
4847
.toDataFrame()
4948
.getColumn<C>(path(), context.unresolvedColumnsPolicy)

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/columns/ColumnSet.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public interface ColumnSet<out C> {
2626
*/
2727
public fun resolveAfterTransform(
2828
context: ColumnResolutionContext,
29-
transform: (List<ColumnWithPath<*>>) -> List<ColumnWithPath<*>>,
29+
transform: (ColumnSet<*>) -> ColumnSet<*>,
3030
): List<ColumnWithPath<C>>
3131
}
3232

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/columns/SingleColumn.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ public interface SingleColumn<out C> : ColumnSet<C> {
1515

1616
override fun resolveAfterTransform(
1717
context: ColumnResolutionContext,
18-
transform: (List<ColumnWithPath<*>>) -> List<ColumnWithPath<*>>,
18+
transform: (ColumnSet<*>) -> ColumnSet<*>,
1919
): List<ColumnWithPath<C>> = resolveSingleAfter(context, transform)?.let { listOf(it) } ?: emptyList()
2020

2121
public fun resolveSingle(context: ColumnResolutionContext): ColumnWithPath<C>?
2222

2323
public fun resolveSingleAfter(
2424
context: ColumnResolutionContext,
25-
transform: (List<ColumnWithPath<*>>) -> List<ColumnWithPath<*>>,
25+
transform: (ColumnSet<*>) -> ColumnSet<*>,
2626
): ColumnWithPath<C>?
2727
}

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/DataFrameReceiver.kt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.jetbrains.kotlinx.dataframe.columns.*
66
import org.jetbrains.kotlinx.dataframe.impl.columns.ColumnGroupWithParent
77
import org.jetbrains.kotlinx.dataframe.impl.columns.ColumnGroupWithPathImpl
88
import org.jetbrains.kotlinx.dataframe.impl.columns.addPath
9+
import org.jetbrains.kotlinx.dataframe.impl.columns.createColumnSet
910
import org.jetbrains.kotlinx.dataframe.impl.columns.missing.MissingColumnGroup
1011
import org.jetbrains.kotlinx.dataframe.impl.columns.missing.MissingDataColumn
1112

@@ -56,18 +57,14 @@ internal open class DataFrameReceiver<T>(
5657

5758
override fun resolveSingleAfter(
5859
context: ColumnResolutionContext,
59-
transform: (List<ColumnWithPath<*>>) -> List<ColumnWithPath<*>>,
60+
transform: (ColumnSet<*>) -> ColumnSet<*>,
6061
): ColumnWithPath<DataRow<T>>? =
6162
DataColumn.createColumnGroup(
6263
name = "",
63-
df = df
64-
.columns()
65-
.map { it.addPath(emptyPath()) }
66-
.let { it as List<ColumnWithPath<DataRow<T>>> }
67-
.let(transform)
68-
.toDataFrame {
69-
70-
} as DataFrame<T>,
64+
df = createColumnSet { df.columns().map { it.addPath() } }
65+
.let(transform).cast<T>()
66+
.resolve(context)
67+
.toDataFrame() as DataFrame<T>,
7168
).addPath(emptyPath())
7269

7370
override fun columns() =

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/ConfiguredAggregateColumn.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.jetbrains.kotlinx.dataframe.impl.aggregation
22

3+
import org.jetbrains.kotlinx.dataframe.api.cast
34
import org.jetbrains.kotlinx.dataframe.columns.*
45
import org.jetbrains.kotlinx.dataframe.impl.columns.transform
56

@@ -31,9 +32,9 @@ internal class ConfiguredAggregateColumn<C> private constructor(
3132

3233
override fun resolveAfterTransform(
3334
context: ColumnResolutionContext,
34-
transform: (List<ColumnWithPath<*>>) -> List<ColumnWithPath<*>>,
35+
transform: (ColumnSet<*>) -> ColumnSet<*>,
3536
): List<ColumnWithPath<C>> =
36-
resolve(context, columns.transform(transform) as ColumnSet<C>)
37+
resolve(context, transform(columns).cast<C>())
3738

3839
companion object {
3940

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/pivot.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ internal class PivotChainColumnSet<C>(val first: ColumnSet<C>, val second: Colum
5353

5454
override fun resolveAfterTransform(
5555
context: ColumnResolutionContext,
56-
transform: (List<ColumnWithPath<*>>) -> List<ColumnWithPath<*>>,
56+
transform: (ColumnSet<*>) -> ColumnSet<*>,
5757
): List<ColumnWithPath<C>> {
5858
throw UnsupportedOperationException("Not implemented")
5959
}

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/sort.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ internal class ColumnsWithSortFlag<C>(val column: ColumnSet<C>, val flag: SortFl
112112

113113
override fun resolveAfterTransform(
114114
context: ColumnResolutionContext,
115-
transform: (List<ColumnWithPath<*>>) -> List<ColumnWithPath<*>>,
115+
transform: (ColumnSet<*>) -> ColumnSet<*>,
116116
): List<ColumnWithPath<C>> = column
117-
.transform { transform(it) as List<ColumnWithPath<C>> }
117+
.let { transform(it) as ColumnSet<C> }
118118
.resolve(context)
119119
.map { it.addFlag(flag) }
120120
}

0 commit comments

Comments
 (0)