@@ -8,14 +8,15 @@ import kotlinx.datetime.toLocalDateTime
8
8
import org.jetbrains.kotlinx.dataframe.AnyBaseCol
9
9
import org.jetbrains.kotlinx.dataframe.AnyCol
10
10
import org.jetbrains.kotlinx.dataframe.AnyFrame
11
+ import org.jetbrains.kotlinx.dataframe.ColumnsContainer
11
12
import org.jetbrains.kotlinx.dataframe.ColumnsSelector
12
13
import org.jetbrains.kotlinx.dataframe.DataColumn
13
14
import org.jetbrains.kotlinx.dataframe.DataFrame
15
+ import org.jetbrains.kotlinx.dataframe.DataRow
14
16
import org.jetbrains.kotlinx.dataframe.RowColumnExpression
15
17
import org.jetbrains.kotlinx.dataframe.RowValueExpression
16
- import org.jetbrains.kotlinx.dataframe.annotations.HasSchema
17
- import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
18
- import org.jetbrains.kotlinx.dataframe.annotations.Refine
18
+ import org.jetbrains.kotlinx.dataframe.annotations.*
19
+ import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
19
20
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
20
21
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
21
22
import org.jetbrains.kotlinx.dataframe.dataTypes.IFRAME
@@ -36,17 +37,19 @@ import org.jetbrains.kotlinx.dataframe.path
36
37
import java.math.BigDecimal
37
38
import java.net.URL
38
39
import java.time.LocalTime
39
- import java.util.Locale
40
+ import java.util.*
40
41
import kotlin.reflect.KProperty
41
42
import kotlin.reflect.KType
42
43
import kotlin.reflect.full.isSubtypeOf
43
44
import kotlin.reflect.full.withNullability
44
45
import kotlin.reflect.typeOf
45
46
46
47
@Interpretable(" Convert0" )
47
- public fun <T , C > DataFrame<T>.convert (columns : ColumnsSelector <T , C >): Convert <T , C > = Convert (this , columns)
48
+ public fun <T , C > DataFrame<T>.convert (columns : ColumnsSelector <T , C >): Convert <T , C > =
49
+ Convert (this , columns)
48
50
49
- public fun <T , C > DataFrame<T>.convert (vararg columns : KProperty <C >): Convert <T , C > = convert { columns.toColumnSet() }
51
+ public fun <T , C > DataFrame<T>.convert (vararg columns : KProperty <C >): Convert <T , C > =
52
+ convert { columns.toColumnSet() }
50
53
51
54
@Interpretable(" Convert2" )
52
55
public fun <T > DataFrame<T>.convert (vararg columns : String ): Convert <T , Any ?> = convert { columns.toColumnSet() }
@@ -59,32 +62,30 @@ public inline fun <T, C, reified R> DataFrame<T>.convert(
59
62
vararg cols : ColumnReference <C >,
60
63
infer : Infer = Infer .Nulls ,
61
64
noinline expression : RowValueExpression <T , C , R >,
62
- ): DataFrame <T > = convert(* headPlusArray(firstCol, cols)).with (infer, expression)
65
+ ): DataFrame <T > =
66
+ convert(* headPlusArray(firstCol, cols)).with (infer, expression)
63
67
64
68
public inline fun <T , C , reified R > DataFrame<T>.convert (
65
69
firstCol : KProperty <C >,
66
70
vararg cols : KProperty <C >,
67
71
infer : Infer = Infer .Nulls ,
68
72
noinline expression : RowValueExpression <T , C , R >,
69
- ): DataFrame <T > = convert(* headPlusArray(firstCol, cols)).with (infer, expression)
73
+ ): DataFrame <T > =
74
+ convert(* headPlusArray(firstCol, cols)).with (infer, expression)
70
75
71
76
@Interpretable(" Convert6" )
72
77
public inline fun <T , reified R > DataFrame<T>.convert (
73
78
firstCol : String ,
74
79
vararg cols : String ,
75
80
infer : Infer = Infer .Nulls ,
76
81
noinline expression : RowValueExpression <T , Any ?, R >,
77
- ): DataFrame <T > = convert(* headPlusArray(firstCol, cols)).with (infer, expression)
78
-
79
- public inline fun <T , C , reified R > Convert <T , C ?>.notNull (
80
- crossinline expression : RowValueExpression <T , C , R >,
81
82
): DataFrame <T > =
83
+ convert(* headPlusArray(firstCol, cols)).with (infer, expression)
84
+
85
+ public inline fun <T , C , reified R > Convert <T , C ?>.notNull (crossinline expression : RowValueExpression <T , C , R >): DataFrame <T > =
82
86
with {
83
- if (it == null ) {
84
- null
85
- } else {
86
- expression(this , it)
87
- }
87
+ if (it == null ) null
88
+ else expression(this , it)
88
89
}
89
90
90
91
@HasSchema(schemaArg = 0 )
@@ -104,25 +105,29 @@ public fun <T, C> Convert<T, C>.to(columnConverter: DataFrame<T>.(DataColumn<C>)
104
105
public inline fun <T , C , reified R > Convert <T , C >.with (
105
106
infer : Infer = Infer .Nulls ,
106
107
noinline rowConverter : RowValueExpression <T , C , R >,
107
- ): DataFrame <T > = withRowCellImpl(typeOf<R >(), infer, rowConverter)
108
+ ): DataFrame <T > =
109
+ withRowCellImpl(typeOf<R >(), infer, rowConverter)
108
110
109
111
@Refine
110
112
@Interpretable(" With0" )
111
113
public inline fun <T , C , reified R > Convert <T , C >.with (
112
- noinline rowConverter : RowValueExpression <T , C , R >,
114
+ noinline rowConverter : RowValueExpression <T , C , R >
113
115
): DataFrame <T > = with (Infer .Nulls , rowConverter)
114
116
117
+ public fun <T , C , R > Convert <T , DataRow <C >>.asFrame (body : ColumnsContainer <T >.(ColumnGroup <C >) -> DataFrame <R >): DataFrame <T > =
118
+ to { body(this , it.asColumnGroup()).asColumnGroup(it.name()) }
119
+
115
120
public inline fun <T , C , reified R > Convert <T , C >.perRowCol (
116
121
infer : Infer = Infer .Nulls ,
117
122
noinline expression : RowColumnExpression <T , C , R >,
118
- ): DataFrame <T > = convertRowColumnImpl(typeOf<R >(), infer, expression)
123
+ ): DataFrame <T > =
124
+ convertRowColumnImpl(typeOf<R >(), infer, expression)
119
125
120
126
public inline fun <reified C > AnyCol.convertTo (): DataColumn <C > = convertTo(typeOf<C >()) as DataColumn <C >
121
127
122
128
public fun AnyCol.convertTo (newType : KType ): AnyCol {
123
- val isTypesAreCorrect =
124
- this .type().withNullability(true ).isSubtypeOf(typeOf<String ?>()) &&
125
- newType.withNullability(true ) == typeOf<Double ?>()
129
+ val isTypesAreCorrect = this .type().withNullability(true )
130
+ .isSubtypeOf(typeOf<String ?>()) && newType.withNullability(true ) == typeOf<Double ?>()
126
131
127
132
if (isTypesAreCorrect) {
128
133
return (this as DataColumn <String ?>).convertToDouble().setNullable(newType.isMarkedNullable)
@@ -181,8 +186,9 @@ public fun <T : Any> DataColumn<T?>.convertToDouble(): DataColumn<Double?> = con
181
186
* If [locale] parameter is null, the current system locale is used. If column can not be parsed, then POSIX format is used.
182
187
*/
183
188
@JvmName(" convertToDoubleFromString" )
184
- public fun DataColumn<String>.convertToDouble (locale : Locale ? = null): DataColumn <Double > =
185
- this .castToNullable().convertToDouble(locale).castToNotNullable()
189
+ public fun DataColumn<String>.convertToDouble (locale : Locale ? = null): DataColumn <Double > {
190
+ return this .castToNullable().convertToDouble(locale).castToNotNullable()
191
+ }
186
192
187
193
/* *
188
194
* Parse String column to Double considering locale (number format).
@@ -201,7 +207,7 @@ public fun DataColumn<String?>.convertToDouble(locale: Locale? = null): DataColu
201
207
value = value,
202
208
from = typeOf<String >(),
203
209
to = typeOf<Double >(),
204
- column = path,
210
+ column = path
205
211
)
206
212
}
207
213
}
@@ -254,21 +260,29 @@ public fun <T, R : URL?> Convert<T, R>.toImg(width: Int? = null, height: Int? =
254
260
255
261
// region toURL
256
262
257
- public fun DataColumn<String>.convertToURL (): DataColumn <URL > = map { URL (it) }
263
+ public fun DataColumn<String>.convertToURL (): DataColumn <URL > {
264
+ return map { URL (it) }
265
+ }
258
266
259
267
@JvmName(" convertToURLFromStringNullable" )
260
- public fun DataColumn<String?>.convertToURL (): DataColumn <URL ?> = map { it?.let { URL (it) } }
268
+ public fun DataColumn<String?>.convertToURL (): DataColumn <URL ?> {
269
+ return map { it?.let { URL (it) } }
270
+ }
261
271
262
272
public fun <T , R : String ?> Convert <T , R >.toURL (): DataFrame <T > = to { it.convertToURL() }
263
273
264
274
// endregion
265
275
266
276
// region toInstant
267
277
268
- public fun DataColumn<String>.convertToInstant (): DataColumn <Instant > = map { Instant .parse(it) }
278
+ public fun DataColumn<String>.convertToInstant (): DataColumn <Instant > {
279
+ return map { Instant .parse(it) }
280
+ }
269
281
270
282
@JvmName(" convertToInstantFromStringNullable" )
271
- public fun DataColumn<String?>.convertToInstant (): DataColumn <Instant ?> = map { it?.let { Instant .parse(it) } }
283
+ public fun DataColumn<String?>.convertToInstant (): DataColumn <Instant ?> {
284
+ return map { it?.let { Instant .parse(it) } }
285
+ }
272
286
273
287
public fun <T , R : String ?> Convert <T , R >.toInstant (): DataFrame <T > = to { it.convertToInstant() }
274
288
0 commit comments