@@ -15,7 +15,9 @@ import org.jetbrains.kotlinx.dataframe.DataFrame
1515import org.jetbrains.kotlinx.dataframe.DataRow
1616import org.jetbrains.kotlinx.dataframe.RowColumnExpression
1717import 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
1921import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
2022import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
2123import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
@@ -37,19 +39,17 @@ import org.jetbrains.kotlinx.dataframe.path
3739import java.math.BigDecimal
3840import java.net.URL
3941import java.time.LocalTime
40- import java.util.*
42+ import java.util.Locale
4143import kotlin.reflect.KProperty
4244import kotlin.reflect.KType
4345import kotlin.reflect.full.isSubtypeOf
4446import kotlin.reflect.full.withNullability
4547import kotlin.reflect.typeOf
4648
4749@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)
5051
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() }
5353
5454@Interpretable(" Convert2" )
5555public 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(
6262 vararg cols : ColumnReference <C >,
6363 infer : Infer = Infer .Nulls ,
6464 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)
6766
6867public inline fun <T , C , reified R > DataFrame<T>.convert (
6968 firstCol : KProperty <C >,
7069 vararg cols : KProperty <C >,
7170 infer : Infer = Infer .Nulls ,
7271 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)
7573
7674@Interpretable(" Convert6" )
7775public inline fun <T , reified R > DataFrame<T>.convert (
7876 firstCol : String ,
7977 vararg cols : String ,
8078 infer : Infer = Infer .Nulls ,
8179 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)
8481
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 > =
8685 with {
87- if (it == null ) null
88- else expression(this , it)
86+ if (it == null ) {
87+ null
88+ } else {
89+ expression(this , it)
90+ }
8991 }
9092
9193@HasSchema(schemaArg = 0 )
@@ -105,29 +107,28 @@ public fun <T, C> Convert<T, C>.to(columnConverter: DataFrame<T>.(DataColumn<C>)
105107public inline fun <T , C , reified R > Convert <T , C >.with (
106108 infer : Infer = Infer .Nulls ,
107109 noinline rowConverter : RowValueExpression <T , C , R >,
108- ): DataFrame <T > =
109- withRowCellImpl(typeOf<R >(), infer, rowConverter)
110+ ): DataFrame <T > = withRowCellImpl(typeOf<R >(), infer, rowConverter)
110111
111112@Refine
112113@Interpretable(" With0" )
113114public inline fun <T , C , reified R > Convert <T , C >.with (
114- noinline rowConverter : RowValueExpression <T , C , R >
115+ noinline rowConverter : RowValueExpression <T , C , R >,
115116): DataFrame <T > = with (Infer .Nulls , rowConverter)
116117
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()) }
119121
120122public inline fun <T , C , reified R > Convert <T , C >.perRowCol (
121123 infer : Infer = Infer .Nulls ,
122124 noinline expression : RowColumnExpression <T , C , R >,
123- ): DataFrame <T > =
124- convertRowColumnImpl(typeOf<R >(), infer, expression)
125+ ): DataFrame <T > = convertRowColumnImpl(typeOf<R >(), infer, expression)
125126
126127public inline fun <reified C > AnyCol.convertTo (): DataColumn <C > = convertTo(typeOf<C >()) as DataColumn <C >
127128
128129public 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 ?>()
131132
132133 if (isTypesAreCorrect) {
133134 return (this as DataColumn <String ?>).convertToDouble().setNullable(newType.isMarkedNullable)
@@ -186,9 +187,8 @@ public fun <T : Any> DataColumn<T?>.convertToDouble(): DataColumn<Double?> = con
186187 * If [locale] parameter is null, the current system locale is used. If column can not be parsed, then POSIX format is used.
187188 */
188189@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()
192192
193193/* *
194194 * Parse String column to Double considering locale (number format).
@@ -207,7 +207,7 @@ public fun DataColumn<String?>.convertToDouble(locale: Locale? = null): DataColu
207207 value = value,
208208 from = typeOf<String >(),
209209 to = typeOf<Double >(),
210- column = path
210+ column = path,
211211 )
212212 }
213213 }
@@ -260,29 +260,21 @@ public fun <T, R : URL?> Convert<T, R>.toImg(width: Int? = null, height: Int? =
260260
261261// region toURL
262262
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) }
266264
267265@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) } }
271267
272268public fun <T , R : String ?> Convert <T , R >.toURL (): DataFrame <T > = to { it.convertToURL() }
273269
274270// endregion
275271
276272// region toInstant
277273
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) }
281275
282276@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) } }
286278
287279public fun <T , R : String ?> Convert <T , R >.toInstant (): DataFrame <T > = to { it.convertToInstant() }
288280
0 commit comments