@@ -7,6 +7,8 @@ import org.jetbrains.kotlinx.dataframe.DataColumn
7
7
import org.jetbrains.kotlinx.dataframe.DataFrame
8
8
import org.jetbrains.kotlinx.dataframe.DataRow
9
9
import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
10
+ import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
11
+ import org.jetbrains.kotlinx.dataframe.annotations.Refine
10
12
import org.jetbrains.kotlinx.dataframe.columns.ColumnAccessor
11
13
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
12
14
import org.jetbrains.kotlinx.dataframe.columns.ColumnSet
@@ -23,6 +25,7 @@ import kotlin.reflect.KProperty
23
25
import kotlin.reflect.KType
24
26
import kotlin.reflect.typeOf
25
27
28
+ @Interpretable(" Split0" )
26
29
public fun <T , C > DataFrame<T>.split (columns : ColumnsSelector <T , C ?>): Split <T , C > = Split (this , columns)
27
30
28
31
public fun <T > DataFrame<T>.split (vararg columns : String ): Split <T , Any > = split { columns.toColumnSet() }
@@ -63,23 +66,27 @@ public typealias ColumnNamesGenerator<C> = ColumnWithPath<C>.(extraColumnIndex:
63
66
64
67
// region default
65
68
69
+ @Interpretable(" SplitDefault" )
66
70
public inline fun <T , C : Iterable <R >, reified R > Split <T , C >.default (value : R ? ): SplitWithTransform <T , C , R > =
67
71
by { it }.default(value)
68
72
69
73
@Deprecated(SPLIT_STR , ReplaceWith (""" by(",").default(value)""" ))
70
74
public fun <T > Split <T , String >.default (value : String? ): SplitWithTransform <T , String , String > =
71
75
by { it.splitDefault() }.default(value)
72
76
77
+ @Interpretable(" SplitWithTransformDefault" )
73
78
public fun <T , C , R > SplitWithTransform <T , C , R >.default (value : R ? ): SplitWithTransform <T , C , R > = copy(default = value)
74
79
75
80
// endregion
76
81
77
82
// region by
78
83
84
+ @Interpretable(" ByIterable" )
79
85
public inline fun <T , C , reified R > Split <T , C >.by (
80
86
noinline splitter : DataRow <T >.(C ) -> Iterable <R >,
81
87
): SplitWithTransform <T , C , R > = by(typeOf<R >(), splitter)
82
88
89
+ @Interpretable(" ByCharDelimiters" )
83
90
public fun <T , C > Split <T , C >.by (
84
91
vararg delimiters : Char ,
85
92
trim : Boolean = true,
@@ -92,6 +99,7 @@ public fun <T, C> Split<T, C>.by(
92
99
}
93
100
}
94
101
102
+ @Interpretable(" ByRegex" )
95
103
public fun <T , C > Split <T , C >.by (
96
104
regex : Regex ,
97
105
trim : Boolean = true,
@@ -103,6 +111,7 @@ public fun <T, C> Split<T, C>.by(
103
111
}
104
112
}
105
113
114
+ @Interpretable(" ByStringDelimiters" )
106
115
public fun <T , C > Split <T , C >.by (
107
116
vararg delimiters : String ,
108
117
trim : Boolean = true,
@@ -133,13 +142,15 @@ internal inline fun <T, C, R> Split<T, C>.by(
133
142
* Created columns will be nullable if [regex] doesn't match some rows or there are nulls in original column
134
143
* Check [Split.by] overload with regex parameter if you're looking to split String value by [Regex] delimiter
135
144
*/
145
+ @Interpretable(" MatchStringRegex" )
136
146
public fun <T , C : String ?> Split <T , C >.match (
137
147
@Language(" RegExp" ) regex : String ,
138
148
): SplitWithTransform <T , C , String ?> = match(regex.toRegex())
139
149
140
150
/* *
141
151
* @include [match]
142
152
*/
153
+ @Interpretable(" MatchRegex" )
143
154
public fun <T , C : String ?> Split <T , C >.match (regex : Regex ): SplitWithTransform <T , C , String ?> =
144
155
by {
145
156
it?.let {
@@ -181,6 +192,8 @@ public fun <T, C, R> SplitWithTransform<T, C, R>.into(
181
192
vararg otherNames : KProperty <* >,
182
193
): DataFrame <T > = into(listOf (firstName.columnName) + otherNames.map { it.columnName })
183
194
195
+ @Refine
196
+ @Interpretable(" SplitWithTransformInto0" )
184
197
public fun <T , C , R > SplitWithTransform <T , C , R >.into (
185
198
vararg names : String ,
186
199
extraNamesGenerator : (ColumnWithPath <C >.(extraColumnIndex: Int ) -> String )? = null,
@@ -198,6 +211,8 @@ public fun <T, C, R> SplitWithTransform<T, C, R>.into(
198
211
}
199
212
}
200
213
214
+ @Refine
215
+ @Interpretable(" SplitIterableInto" )
201
216
public fun <T , C : Iterable <* >> Split <T , C >.into (
202
217
vararg names : String ,
203
218
extraNamesGenerator : ColumnNamesGenerator <C >? = null,
@@ -209,6 +224,8 @@ public fun <T, C> Split<T, DataFrame<C>>.into(
209
224
extraNamesGenerator : ColumnNamesGenerator <DataFrame <C >>? = null,
210
225
): DataFrame <T > = by { it.rows() }.into(names.toList(), extraNamesGenerator)
211
226
227
+ @Refine
228
+ @Interpretable(" SplitPair" )
212
229
public fun <T , A , B > Split <T , Pair <A , B >>.into (firstCol : String , secondCol : String ): DataFrame <T > =
213
230
by { listOf (it.first, it.second) }.into(firstCol, secondCol)
214
231
@@ -237,6 +254,8 @@ public fun <T, C, R> SplitWithTransform<T, C, R>.inward(
237
254
extraNamesGenerator : ColumnNamesGenerator <C >? = null,
238
255
): DataFrame <T > = copy(inward = true ).into(names.toList(), extraNamesGenerator)
239
256
257
+ @Refine
258
+ @Interpretable(" SplitWithTransformInward0" )
240
259
public fun <T , C , R > SplitWithTransform <T , C , R >.inward (
241
260
vararg names : String ,
242
261
extraNamesGenerator : ColumnNamesGenerator <C >? = null,
@@ -294,6 +313,8 @@ public fun <T> Split<T, String>.inward(
294
313
295
314
// region intoColumns
296
315
316
+ @Refine
317
+ @Interpretable(" SplitAnyFrameIntoColumns" )
297
318
public fun <T , C : AnyFrame > Split <T , C >.intoColumns (): DataFrame <T > =
298
319
df.convert(columns).with {
299
320
when {
@@ -308,11 +329,15 @@ public fun <T, C : AnyFrame> Split<T, C>.intoColumns(): DataFrame<T> =
308
329
// region intoRows
309
330
310
331
@JvmName(" intoRowsTC" )
332
+ @Refine
333
+ @Interpretable(" SplitIntoRows" )
311
334
public inline fun <T , C : Iterable <R >, reified R > Split <T , C >.intoRows (dropEmpty : Boolean = true): DataFrame <T > =
312
335
by { it }
313
336
.intoRows(dropEmpty)
314
337
315
338
@JvmName(" intoRowsFrame" )
339
+ @Refine
340
+ @Interpretable(" SplitAnyFrameRows" )
316
341
public fun <T , C : AnyFrame > Split <T , C >.intoRows (dropEmpty : Boolean = true): DataFrame <T > =
317
342
by { it.rows() }.intoRows(dropEmpty)
318
343
@@ -321,6 +346,8 @@ internal inline fun <T, C, R> Convert<T, C?>.splitInplace(
321
346
crossinline transform : DataRow <T >.(C ) -> Iterable <R >,
322
347
) = withRowCellImpl(getListType(type), Infer .None ) { if (it == null ) emptyList() else transform(it).asList() }
323
348
349
+ @Refine
350
+ @Interpretable(" SplitWithTransformIntoRows" )
324
351
public fun <T , C , R > SplitWithTransform <T , C , R >.intoRows (dropEmpty : Boolean = true): DataFrame <T > {
325
352
val paths = df.getColumnPaths(columns).toColumnSet()
326
353
return df.convert { paths as ColumnSet <C ?> }.splitInplace(tartypeOf, transform).explode(dropEmpty) { paths }
@@ -331,8 +358,12 @@ public fun <T, C, R> SplitWithTransform<T, C, R>.intoRows(dropEmpty: Boolean = t
331
358
// region inplace
332
359
333
360
@JvmName(" inplaceTC" )
361
+ @Refine
362
+ @Interpretable(" SplitInplace" )
334
363
public inline fun <T , C : Iterable <R >, reified R > Split <T , C >.inplace (): DataFrame <T > = by { it }.inplace()
335
364
365
+ @Refine
366
+ @Interpretable(" SplitWithTransformInplace" )
336
367
public fun <T , C , R > SplitWithTransform <T , C , R >.inplace (): DataFrame <T > =
337
368
df.convert(columns).splitInplace(tartypeOf, transform)
338
369
0 commit comments