Skip to content

Commit f02bd29

Browse files
Automated commit of generated code
1 parent c4c028c commit f02bd29

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/cast.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public inline fun <reified T> AnyFrame.cast(verify: Boolean = true): DataFrame<T
3434
else cast()
3535

3636
public inline fun <reified T> AnyFrame.castTo(
37-
@Suppress("UNUSED_PARAMETER") df: DataFrame<T>,
37+
@Suppress("UNUSED_PARAMETER") schemaFrom: DataFrame<T>,
3838
verify: Boolean = true
3939
): DataFrame<T> {
4040
return cast<T>(verify = verify)

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/convertTo.kt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,43 @@ public inline fun <reified T : Any> AnyFrame.convertTo(
161161
noinline body: ConvertSchemaDsl<T>.() -> Unit = {}
162162
): DataFrame<T> = convertToImpl(typeOf<T>(), true, excessiveColumnsBehavior, body).cast()
163163

164+
/**
165+
* Converts values in [DataFrame] to match given column schema [T].
166+
*
167+
* Original columns are mapped to destination columns by column [path][DataColumn.path].
168+
*
169+
* Type converters for every column are selected automatically. See [convert] operation for details.
170+
*
171+
* To specify custom type converters for the particular types use [ConvertSchemaDsl].
172+
*
173+
* Example of Dsl:
174+
* ```kotlin
175+
* df.convertTo(schemaFrom = sample) {
176+
* // defines how to convert Int? -> String
177+
* convert<Int?>().with { it?.toString() ?: "No input given" }
178+
* // defines how to convert String -> SomeType
179+
* parser { SomeType(it) }
180+
* // fill missing column `sum` with expression `a + b`
181+
* fill { sum }.with { a + b }
182+
* }
183+
* ```
184+
*
185+
* @param [T] class that defines target schema for conversion.
186+
* @param [schemaFrom] dataframe which type [T] will be used.
187+
* @param [excessiveColumnsBehavior] how to handle excessive columns in the original [DataFrame].
188+
* @param [body] optional dsl to define custom type converters.
189+
* @throws [ColumnNotFoundException] if [DataFrame] doesn't contain columns that are required by destination schema.
190+
* @throws [ExcessiveColumnsException] if [DataFrame] contains columns that are not required by destination schema and [excessiveColumnsBehavior] is set to [ExcessiveColumns.Fail].
191+
* @throws [TypeConverterNotFoundException] if suitable type converter for some column was not found.
192+
* @throws [TypeConversionException] if type converter failed to convert column values.
193+
* @return converted [DataFrame].
194+
*/
195+
public inline fun <reified T : Any> AnyFrame.convertTo(
196+
@Suppress("UNUSED_PARAMETER") schemaFrom: DataFrame<T>,
197+
excessiveColumnsBehavior: ExcessiveColumns = ExcessiveColumns.Keep,
198+
noinline body: ConvertSchemaDsl<T>.() -> Unit = {}
199+
): DataFrame<T> = convertToImpl(typeOf<T>(), true, excessiveColumnsBehavior, body).cast()
200+
164201
/**
165202
* Converts values in [DataFrame] to match given column schema [schemaType].
166203
*

0 commit comments

Comments
 (0)