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