Skip to content

Commit 8f10093

Browse files
authored
Merge pull request #279 from Kotlin/column-typealias-rename
Rename Column typealias to AnyColumnReference
2 parents a089dcb + d162d43 commit 8f10093

25 files changed

+94
-90
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/DataFrame.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public interface DataFrame<out T> : Aggregatable<T>, ColumnsContainer<T> {
5757
override operator fun <C> get(columns: ColumnsSelector<T, C>): List<DataColumn<C>> =
5858
getColumnsImpl(UnresolvedColumnsPolicy.Fail, columns)
5959

60-
public operator fun get(first: Column, vararg other: Column): DataFrame<T> = select(listOf(first) + other)
60+
public operator fun get(first: AnyColumnReference, vararg other: AnyColumnReference): DataFrame<T> = select(listOf(first) + other)
6161
public operator fun get(first: String, vararg other: String): DataFrame<T> = select(listOf(first) + other)
6262
public operator fun get(columnRange: ClosedRange<String>): DataFrame<T> =
6363
select { columnRange.start..columnRange.endInclusive }

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/DataRow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public interface DataRow<out T> {
2828
public operator fun <R> get(column: ColumnReference<R>): R
2929
public operator fun <R> get(columns: List<ColumnReference<R>>): List<R> = columns.map { get(it) }
3030
public operator fun <R> get(property: KProperty<R>): R = get(property.columnName) as R
31-
public operator fun get(first: Column, vararg other: Column): DataRow<T> = owner.get(first, *other)[index]
31+
public operator fun get(first: AnyColumnReference, vararg other: AnyColumnReference): DataRow<T> = owner.get(first, *other)[index]
3232
public operator fun get(first: String, vararg other: String): DataRow<T> = owner.get(first, *other)[index]
3333
public operator fun get(path: ColumnPath): Any? = owner.get(path)[index]
3434
public operator fun get(name: String): Any?

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/aliases.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public typealias RowValueFilter<T, C> = RowValueExpression<T, C, Boolean>
138138

139139
// region columns
140140

141-
public typealias Column = ColumnReference<*>
141+
public typealias AnyColumnReference = ColumnReference<*>
142142

143143
public typealias ColumnGroupReference = ColumnReference<AnyRow>
144144
public typealias ColumnGroupAccessor<T> = ColumnAccessor<DataRow<T>>

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package org.jetbrains.kotlinx.dataframe.api
22

3-
import org.jetbrains.kotlinx.dataframe.*
3+
import org.jetbrains.kotlinx.dataframe.AnyCol
4+
import org.jetbrains.kotlinx.dataframe.AnyColumnReference
5+
import org.jetbrains.kotlinx.dataframe.AnyRow
46
import org.jetbrains.kotlinx.dataframe.ColumnFilter
7+
import org.jetbrains.kotlinx.dataframe.ColumnGroupReference
58
import org.jetbrains.kotlinx.dataframe.ColumnsContainer
69
import org.jetbrains.kotlinx.dataframe.ColumnsSelector
710
import org.jetbrains.kotlinx.dataframe.DataColumn
11+
import org.jetbrains.kotlinx.dataframe.DataFrame
12+
import org.jetbrains.kotlinx.dataframe.DataRow
813
import org.jetbrains.kotlinx.dataframe.Predicate
914
import org.jetbrains.kotlinx.dataframe.columns.ColumnAccessor
1015
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
@@ -16,6 +21,7 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath
1621
import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
1722
import org.jetbrains.kotlinx.dataframe.columns.SingleColumn
1823
import org.jetbrains.kotlinx.dataframe.columns.renamedReference
24+
import org.jetbrains.kotlinx.dataframe.hasNulls
1925
import org.jetbrains.kotlinx.dataframe.impl.columnName
2026
import org.jetbrains.kotlinx.dataframe.impl.columns.ColumnsList
2127
import org.jetbrains.kotlinx.dataframe.impl.columns.DistinctColumnSet
@@ -31,7 +37,6 @@ import org.jetbrains.kotlinx.dataframe.impl.columns.top
3137
import org.jetbrains.kotlinx.dataframe.impl.columns.transform
3238
import org.jetbrains.kotlinx.dataframe.impl.columns.transformSingle
3339
import org.jetbrains.kotlinx.dataframe.impl.columns.tree.dfs
34-
import org.jetbrains.kotlinx.dataframe.impl.getColumnsWithPaths
3540
import kotlin.reflect.KProperty
3641
import kotlin.reflect.KType
3742
import kotlin.reflect.typeOf
@@ -67,7 +72,7 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
6772

6873
public operator fun String.rangeTo(endInclusive: String): ColumnSet<*> = toColumnAccessor().rangeTo(endInclusive.toColumnAccessor())
6974

70-
public operator fun Column.rangeTo(endInclusive: Column): ColumnSet<*> = object : ColumnSet<Any?> {
75+
public operator fun AnyColumnReference.rangeTo(endInclusive: AnyColumnReference): ColumnSet<*> = object : ColumnSet<Any?> {
7176
override fun resolve(context: ColumnResolutionContext): List<ColumnWithPath<Any?>> {
7277
val startPath = this@rangeTo.resolveSingle(context)!!.path
7378
val endPath = endInclusive.resolveSingle(context)!!.path
@@ -161,7 +166,7 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
161166
}
162167

163168
public fun SingleColumn<*>.allAfter(colName: String): ColumnSet<Any?> = allAfter(pathOf(colName))
164-
public fun SingleColumn<*>.allAfter(column: Column): ColumnSet<Any?> = allAfter(column.path())
169+
public fun SingleColumn<*>.allAfter(column: AnyColumnReference): ColumnSet<Any?> = allAfter(column.path())
165170

166171
// endregion
167172

@@ -180,7 +185,7 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
180185
}
181186

182187
public fun SingleColumn<*>.allSince(colName: String): ColumnSet<Any?> = allSince(pathOf(colName))
183-
public fun SingleColumn<*>.allSince(column: Column): ColumnSet<Any?> = allSince(column.path())
188+
public fun SingleColumn<*>.allSince(column: AnyColumnReference): ColumnSet<Any?> = allSince(column.path())
184189

185190
// endregion
186191

@@ -199,7 +204,7 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
199204
}
200205

201206
public fun SingleColumn<*>.allBefore(colName: String): ColumnSet<Any?> = allBefore(pathOf(colName))
202-
public fun SingleColumn<*>.allBefore(column: Column): ColumnSet<Any?> = allBefore(column.path())
207+
public fun SingleColumn<*>.allBefore(column: AnyColumnReference): ColumnSet<Any?> = allBefore(column.path())
203208

204209
// endregion
205210

@@ -218,7 +223,7 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
218223
}
219224

220225
public fun SingleColumn<*>.allUntil(colName: String): ColumnSet<Any?> = allUntil(pathOf(colName))
221-
public fun SingleColumn<*>.allUntil(column: Column): ColumnSet<Any?> = allUntil(column.path())
226+
public fun SingleColumn<*>.allUntil(column: AnyColumnReference): ColumnSet<Any?> = allUntil(column.path())
222227

223228
// endregion
224229

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/DataFrameGet.kt

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

33
import org.jetbrains.kotlinx.dataframe.AnyCol
4-
import org.jetbrains.kotlinx.dataframe.Column
4+
import org.jetbrains.kotlinx.dataframe.AnyColumnReference
55
import org.jetbrains.kotlinx.dataframe.ColumnSelector
66
import org.jetbrains.kotlinx.dataframe.ColumnsContainer
77
import org.jetbrains.kotlinx.dataframe.ColumnsSelector
@@ -19,7 +19,6 @@ import org.jetbrains.kotlinx.dataframe.impl.columns.asAnyFrameColumn
1919
import org.jetbrains.kotlinx.dataframe.impl.columns.toColumns
2020
import org.jetbrains.kotlinx.dataframe.impl.getColumnPaths
2121
import org.jetbrains.kotlinx.dataframe.impl.getColumnsWithPaths
22-
import org.jetbrains.kotlinx.dataframe.indices
2322
import org.jetbrains.kotlinx.dataframe.ncol
2423
import org.jetbrains.kotlinx.dataframe.nrow
2524
import kotlin.reflect.KProperty
@@ -89,7 +88,7 @@ public fun <T> ColumnsContainer<T>.getColumnGroupOrNull(column: KProperty<*>): C
8988
public fun <C> ColumnsContainer<*>.containsColumn(column: ColumnReference<C>): Boolean = getColumnOrNull(column) != null
9089
public fun ColumnsContainer<*>.containsColumn(column: KProperty<*>): Boolean = containsColumn(column.columnName)
9190

92-
public operator fun ColumnsContainer<*>.contains(column: Column): Boolean = containsColumn(column)
91+
public operator fun ColumnsContainer<*>.contains(column: AnyColumnReference): Boolean = containsColumn(column)
9392
public operator fun ColumnsContainer<*>.contains(column: KProperty<*>): Boolean = containsColumn(column)
9493

9594
// region rows

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/DataRowApi.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.jetbrains.kotlinx.dataframe.api
22

3+
import org.jetbrains.kotlinx.dataframe.AnyColumnReference
34
import org.jetbrains.kotlinx.dataframe.AnyRow
4-
import org.jetbrains.kotlinx.dataframe.Column
55
import org.jetbrains.kotlinx.dataframe.ColumnsContainer
66
import org.jetbrains.kotlinx.dataframe.DataColumn
77
import org.jetbrains.kotlinx.dataframe.DataFrame
@@ -57,10 +57,10 @@ public fun <T> AnyRow.getValueOrNull(column: KProperty<T>): T? = getValueOrNull<
5757
// region contains
5858

5959
public fun AnyRow.containsKey(columnName: String): Boolean = owner.containsColumn(columnName)
60-
public fun AnyRow.containsKey(column: Column): Boolean = owner.containsColumn(column)
60+
public fun AnyRow.containsKey(column: AnyColumnReference): Boolean = owner.containsColumn(column)
6161
public fun AnyRow.containsKey(column: KProperty<*>): Boolean = owner.containsColumn(column)
6262

63-
public operator fun AnyRow.contains(column: Column): Boolean = containsKey(column)
63+
public operator fun AnyRow.contains(column: AnyColumnReference): Boolean = containsKey(column)
6464
public operator fun AnyRow.contains(column: KProperty<*>): Boolean = containsKey(column)
6565

6666
// endregion

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/Nulls.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package org.jetbrains.kotlinx.dataframe.api
22

33
import org.jetbrains.kotlinx.dataframe.AnyCol
4+
import org.jetbrains.kotlinx.dataframe.AnyColumnReference
45
import org.jetbrains.kotlinx.dataframe.AnyFrame
56
import org.jetbrains.kotlinx.dataframe.AnyRow
6-
import org.jetbrains.kotlinx.dataframe.Column
77
import org.jetbrains.kotlinx.dataframe.ColumnsSelector
88
import org.jetbrains.kotlinx.dataframe.DataColumn
99
import org.jetbrains.kotlinx.dataframe.DataFrame
@@ -109,10 +109,10 @@ public fun <T> DataFrame<T>.dropNulls(vararg cols: KProperty<*>, whereAllNull: B
109109
public fun <T> DataFrame<T>.dropNulls(vararg cols: String, whereAllNull: Boolean = false): DataFrame<T> =
110110
dropNulls(whereAllNull) { cols.toColumns() }
111111

112-
public fun <T> DataFrame<T>.dropNulls(vararg cols: Column, whereAllNull: Boolean = false): DataFrame<T> =
112+
public fun <T> DataFrame<T>.dropNulls(vararg cols: AnyColumnReference, whereAllNull: Boolean = false): DataFrame<T> =
113113
dropNulls(whereAllNull) { cols.toColumns() }
114114

115-
public fun <T> DataFrame<T>.dropNulls(cols: Iterable<Column>, whereAllNull: Boolean = false): DataFrame<T> =
115+
public fun <T> DataFrame<T>.dropNulls(cols: Iterable<AnyColumnReference>, whereAllNull: Boolean = false): DataFrame<T> =
116116
dropNulls(whereAllNull) { cols.toColumnSet() }
117117

118118
public fun <T> DataColumn<T?>.dropNulls(): DataColumn<T> =
@@ -135,10 +135,10 @@ public fun <T> DataFrame<T>.dropNA(vararg cols: KProperty<*>, whereAllNA: Boolea
135135
public fun <T> DataFrame<T>.dropNA(vararg cols: String, whereAllNA: Boolean = false): DataFrame<T> =
136136
dropNA(whereAllNA) { cols.toColumns() }
137137

138-
public fun <T> DataFrame<T>.dropNA(vararg cols: Column, whereAllNA: Boolean = false): DataFrame<T> =
138+
public fun <T> DataFrame<T>.dropNA(vararg cols: AnyColumnReference, whereAllNA: Boolean = false): DataFrame<T> =
139139
dropNA(whereAllNA) { cols.toColumns() }
140140

141-
public fun <T> DataFrame<T>.dropNA(cols: Iterable<Column>, whereAllNA: Boolean = false): DataFrame<T> =
141+
public fun <T> DataFrame<T>.dropNA(cols: Iterable<AnyColumnReference>, whereAllNA: Boolean = false): DataFrame<T> =
142142
dropNA(whereAllNA) { cols.toColumnSet() }
143143

144144
public fun <T> DataFrame<T>.dropNA(whereAllNA: Boolean = false): DataFrame<T> =

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/add.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package org.jetbrains.kotlinx.dataframe.api
33
import org.jetbrains.kotlinx.dataframe.AnyBaseCol
44
import org.jetbrains.kotlinx.dataframe.AnyCol
55
import org.jetbrains.kotlinx.dataframe.AnyColumnGroupAccessor
6+
import org.jetbrains.kotlinx.dataframe.AnyColumnReference
67
import org.jetbrains.kotlinx.dataframe.AnyFrame
78
import org.jetbrains.kotlinx.dataframe.AnyRow
8-
import org.jetbrains.kotlinx.dataframe.Column
99
import org.jetbrains.kotlinx.dataframe.ColumnsContainer
1010
import org.jetbrains.kotlinx.dataframe.DataColumn
1111
import org.jetbrains.kotlinx.dataframe.DataFrame
@@ -149,9 +149,9 @@ public class AddDsl<T>(@PublishedApi internal val df: DataFrame<T>) : ColumnsCon
149149
// TODO: support adding column into path
150150
internal val columns = mutableListOf<AnyCol>()
151151

152-
public fun add(column: Column): Boolean = columns.add(column.resolveSingle(df)!!.data)
152+
public fun add(column: AnyColumnReference): Boolean = columns.add(column.resolveSingle(df)!!.data)
153153

154-
public operator fun Column.unaryPlus(): Boolean = add(this)
154+
public operator fun AnyColumnReference.unaryPlus(): Boolean = add(this)
155155

156156
public operator fun String.unaryPlus(): Boolean = add(df[this])
157157

@@ -172,11 +172,11 @@ public class AddDsl<T>(@PublishedApi internal val df: DataFrame<T>) : ColumnsCon
172172
public inline infix fun <reified R> ColumnAccessor<R>.from(noinline expression: RowExpression<T, R>): Boolean = name().from(expression)
173173
public inline infix fun <reified R> KProperty<R>.from(noinline expression: RowExpression<T, R>): Boolean = add(name, Infer.Nulls, expression)
174174

175-
public infix fun String.from(column: Column): Boolean = add(column.rename(this))
175+
public infix fun String.from(column: AnyColumnReference): Boolean = add(column.rename(this))
176176
public inline infix fun <reified R> ColumnAccessor<R>.from(column: ColumnReference<R>): Boolean = name() from column
177177
public inline infix fun <reified R> KProperty<R>.from(column: ColumnReference<R>): Boolean = name from column
178178

179-
public infix fun Column.into(name: String): Boolean = add(rename(name))
179+
public infix fun AnyColumnReference.into(name: String): Boolean = add(rename(name))
180180
public infix fun <R> ColumnReference<R>.into(column: ColumnAccessor<R>): Boolean = into(column.name())
181181
public infix fun <R> ColumnReference<R>.into(column: KProperty<R>): Boolean = into(column.name)
182182

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/countDistinct.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.jetbrains.kotlinx.dataframe.api
22

3+
import org.jetbrains.kotlinx.dataframe.AnyColumnReference
34
import org.jetbrains.kotlinx.dataframe.AnyFrame
4-
import org.jetbrains.kotlinx.dataframe.Column
55
import org.jetbrains.kotlinx.dataframe.ColumnsSelector
66
import org.jetbrains.kotlinx.dataframe.DataFrame
77
import org.jetbrains.kotlinx.dataframe.impl.columns.toColumns
@@ -19,6 +19,6 @@ public fun <T, C> DataFrame<T>.countDistinct(columns: ColumnsSelector<T, C>): In
1919

2020
public fun <T> DataFrame<T>.countDistinct(vararg columns: String): Int = countDistinct { columns.toColumns() }
2121
public fun <T, C> DataFrame<T>.countDistinct(vararg columns: KProperty<C>): Int = countDistinct { columns.toColumns() }
22-
public fun <T> DataFrame<T>.countDistinct(vararg columns: Column): Int = countDistinct { columns.toColumns() }
22+
public fun <T> DataFrame<T>.countDistinct(vararg columns: AnyColumnReference): Int = countDistinct { columns.toColumns() }
2323

2424
// endregion

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/cumSum.kt

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

3-
import org.jetbrains.kotlinx.dataframe.Column
3+
import org.jetbrains.kotlinx.dataframe.AnyColumnReference
44
import org.jetbrains.kotlinx.dataframe.ColumnsSelector
55
import org.jetbrains.kotlinx.dataframe.DataColumn
66
import org.jetbrains.kotlinx.dataframe.DataFrame
@@ -38,7 +38,7 @@ private val supportedClasses = setOf(Double::class, Float::class, Int::class, Lo
3838
public fun <T, C> DataFrame<T>.cumSum(skipNA: Boolean = defaultCumSumSkipNA, columns: ColumnsSelector<T, C>): DataFrame<T> =
3939
convert(columns).to { if (it.typeClass in supportedClasses) it.cast<Number?>().cumSum(skipNA) else it }
4040
public fun <T> DataFrame<T>.cumSum(vararg columns: String, skipNA: Boolean = defaultCumSumSkipNA): DataFrame<T> = cumSum(skipNA) { columns.toColumns() }
41-
public fun <T> DataFrame<T>.cumSum(vararg columns: Column, skipNA: Boolean = defaultCumSumSkipNA): DataFrame<T> = cumSum(skipNA) { columns.toColumns() }
41+
public fun <T> DataFrame<T>.cumSum(vararg columns: AnyColumnReference, skipNA: Boolean = defaultCumSumSkipNA): DataFrame<T> = cumSum(skipNA) { columns.toColumns() }
4242
public fun <T> DataFrame<T>.cumSum(vararg columns: KProperty<*>, skipNA: Boolean = defaultCumSumSkipNA): DataFrame<T> = cumSum(skipNA) { columns.toColumns() }
4343

4444
public fun <T> DataFrame<T>.cumSum(skipNA: Boolean = defaultCumSumSkipNA): DataFrame<T> = cumSum(skipNA) { allDfs() }
@@ -50,7 +50,7 @@ public fun <T> DataFrame<T>.cumSum(skipNA: Boolean = defaultCumSumSkipNA): DataF
5050
public fun <T, G, C> GroupBy<T, G>.cumSum(skipNA: Boolean = defaultCumSumSkipNA, columns: ColumnsSelector<G, C>): GroupBy<T, G> =
5151
updateGroups { cumSum(skipNA, columns) }
5252
public fun <T, G> GroupBy<T, G>.cumSum(vararg columns: String, skipNA: Boolean = defaultCumSumSkipNA): GroupBy<T, G> = cumSum(skipNA) { columns.toColumns() }
53-
public fun <T, G> GroupBy<T, G>.cumSum(vararg columns: Column, skipNA: Boolean = defaultCumSumSkipNA): GroupBy<T, G> = cumSum(skipNA) { columns.toColumns() }
53+
public fun <T, G> GroupBy<T, G>.cumSum(vararg columns: AnyColumnReference, skipNA: Boolean = defaultCumSumSkipNA): GroupBy<T, G> = cumSum(skipNA) { columns.toColumns() }
5454
public fun <T, G> GroupBy<T, G>.cumSum(vararg columns: KProperty<*>, skipNA: Boolean = defaultCumSumSkipNA): GroupBy<T, G> = cumSum(skipNA) { columns.toColumns() }
5555
public fun <T, G> GroupBy<T, G>.cumSum(skipNA: Boolean = defaultCumSumSkipNA): GroupBy<T, G> = cumSum(skipNA) { allDfs() }
5656

0 commit comments

Comments
 (0)