1
1
package org.jetbrains.kotlinx.dataframe
2
2
3
- import org.jetbrains.kotlinx.dataframe.api.Infer
4
- import org.jetbrains.kotlinx.dataframe.api.asDataColumn
5
- import org.jetbrains.kotlinx.dataframe.api.cast
6
- import org.jetbrains.kotlinx.dataframe.api.concat
7
- import org.jetbrains.kotlinx.dataframe.api.filter
8
- import org.jetbrains.kotlinx.dataframe.api.schema
9
- import org.jetbrains.kotlinx.dataframe.api.take
10
- import org.jetbrains.kotlinx.dataframe.columns.BaseColumn
11
- import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
12
- import org.jetbrains.kotlinx.dataframe.columns.ColumnKind
13
- import org.jetbrains.kotlinx.dataframe.columns.ColumnPath
14
- import org.jetbrains.kotlinx.dataframe.columns.ColumnResolutionContext
15
- import org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath
16
- import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
17
- import org.jetbrains.kotlinx.dataframe.columns.ValueColumn
18
- import org.jetbrains.kotlinx.dataframe.impl.columns.ColumnGroupImpl
19
- import org.jetbrains.kotlinx.dataframe.impl.columns.FrameColumnImpl
20
- import org.jetbrains.kotlinx.dataframe.impl.columns.ValueColumnImpl
21
- import org.jetbrains.kotlinx.dataframe.impl.columns.addPath
22
- import org.jetbrains.kotlinx.dataframe.impl.columns.guessColumnType
23
- import org.jetbrains.kotlinx.dataframe.impl.columns.toColumnKind
3
+ import org.jetbrains.kotlinx.dataframe.api.*
4
+ import org.jetbrains.kotlinx.dataframe.columns.*
5
+ import org.jetbrains.kotlinx.dataframe.impl.columns.*
24
6
import org.jetbrains.kotlinx.dataframe.impl.getValuesType
25
7
import org.jetbrains.kotlinx.dataframe.impl.splitByIndices
26
8
import org.jetbrains.kotlinx.dataframe.schema.DataFrameSchema
@@ -54,7 +36,7 @@ public interface DataColumn<out T> : BaseColumn<T> {
54
36
values : List <T >,
55
37
type : KType ,
56
38
infer : Infer = Infer .None ,
57
- defaultValue : T ? = null
39
+ defaultValue : T ? = null,
58
40
): ValueColumn <T > = ValueColumnImpl (values, name, getValuesType(values, type, infer), defaultValue)
59
41
60
42
/* *
@@ -67,7 +49,11 @@ public interface DataColumn<out T> : BaseColumn<T> {
67
49
* @param values list of column values
68
50
* @param infer column type inference mode
69
51
*/
70
- public inline fun <reified T > createValueColumn (name : String , values : List <T >, infer : Infer = Infer .None ): ValueColumn <T > = createValueColumn(
52
+ public inline fun <reified T > createValueColumn (
53
+ name : String ,
54
+ values : List <T >,
55
+ infer : Infer = Infer .None ,
56
+ ): ValueColumn <T > = createValueColumn(
71
57
name, values,
72
58
getValuesType(
73
59
values,
@@ -81,17 +67,21 @@ public interface DataColumn<out T> : BaseColumn<T> {
81
67
public fun <T > createFrameColumn (
82
68
name : String ,
83
69
df : DataFrame <T >,
84
- startIndices : Iterable <Int >
70
+ startIndices : Iterable <Int >,
85
71
): FrameColumn <T > =
86
72
FrameColumnImpl (name, df.splitByIndices(startIndices.asSequence()).toList(), lazy { df.schema() })
87
73
88
74
public fun <T > createFrameColumn (
89
75
name : String ,
90
76
groups : List <DataFrame <T >>,
91
- schema : Lazy <DataFrameSchema >? = null
77
+ schema : Lazy <DataFrameSchema >? = null,
92
78
): FrameColumn <T > = FrameColumnImpl (name, groups, schema)
93
79
94
- public fun <T > createWithTypeInference (name : String , values : List <T >, nullable : Boolean? = null): DataColumn <T > = guessColumnType(name, values, nullable = nullable)
80
+ public fun <T > createWithTypeInference (
81
+ name : String ,
82
+ values : List <T >,
83
+ nullable : Boolean? = null,
84
+ ): DataColumn <T > = guessColumnType(name, values, nullable = nullable)
95
85
96
86
public fun <T > create (name : String , values : List <T >, type : KType , infer : Infer = Infer .None ): DataColumn <T > {
97
87
return when (type.toColumnKind()) {
@@ -101,7 +91,8 @@ public interface DataColumn<out T> : BaseColumn<T> {
101
91
}
102
92
}
103
93
104
- public inline fun <reified T > create (name : String , values : List <T >, infer : Infer = Infer .None ): DataColumn <T > = create(name, values, typeOf<T >(), infer)
94
+ public inline fun <reified T > create (name : String , values : List <T >, infer : Infer = Infer .None ): DataColumn <T > =
95
+ create(name, values, typeOf<T >(), infer)
105
96
106
97
public fun empty (name : String = ""): AnyCol = createValueColumn(name, emptyList<Unit >(), typeOf<Unit >())
107
98
}
@@ -116,7 +107,8 @@ public interface DataColumn<out T> : BaseColumn<T> {
116
107
117
108
override fun resolveSingle (context : ColumnResolutionContext ): ColumnWithPath <T >? = this .addPath()
118
109
119
- override operator fun getValue (thisRef : Any? , property : KProperty <* >): DataColumn <T > = super .getValue(thisRef, property) as DataColumn <T >
110
+ override operator fun getValue (thisRef : Any? , property : KProperty <* >): DataColumn <T > =
111
+ super .getValue(thisRef, property) as DataColumn <T >
120
112
121
113
public operator fun iterator (): Iterator <T > = values().iterator()
122
114
@@ -133,6 +125,8 @@ public val AnyCol.indices: IntRange get() = indices()
133
125
134
126
public val AnyCol .type: KType get() = type()
135
127
public val AnyCol .kind: ColumnKind get() = kind()
136
- public val AnyCol .typeClass: KClass <* > get() = type.classifier as ? KClass <* > ? : error(" Cannot cast ${type.classifier?.javaClass} to a ${KClass ::class } . Column $name : $type " )
128
+ public val AnyCol .typeClass: KClass <* >
129
+ get() = type.classifier as ? KClass <* >
130
+ ? : error(" Cannot cast ${type.classifier?.javaClass} to a ${KClass ::class } . Column $name : $type " )
137
131
138
132
public fun AnyBaseCol.indices (): IntRange = 0 until size()
0 commit comments