Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public inline fun <reified T> AnyFrame.cast(verify: Boolean = true): DataFrame<T
else cast()

public inline fun <reified T> AnyFrame.castTo(
@Suppress("UNUSED_PARAMETER") df: DataFrame<T>,
@Suppress("UNUSED_PARAMETER") schemaFrom: DataFrame<T>,
verify: Boolean = true
): DataFrame<T> {
return cast<T>(verify = verify)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,43 @@ public inline fun <reified T : Any> AnyFrame.convertTo(
noinline body: ConvertSchemaDsl<T>.() -> Unit = {}
): DataFrame<T> = convertToImpl(typeOf<T>(), true, excessiveColumnsBehavior, body).cast()

/**
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just copy-pasted it from existing function

* Converts values in [DataFrame] to match given column schema [T].
*
* Original columns are mapped to destination columns by column [path][DataColumn.path].
*
* Type converters for every column are selected automatically. See [convert] operation for details.
*
* To specify custom type converters for the particular types use [ConvertSchemaDsl].
*
* Example of Dsl:
* ```kotlin
* df.convertTo(schemaFrom = sample) {
* // defines how to convert Int? -> String
* convert<Int?>().with { it?.toString() ?: "No input given" }
* // defines how to convert String -> SomeType
* parser { SomeType(it) }
* // fill missing column `sum` with expression `a + b`
* fill { sum }.with { a + b }
* }
* ```
*
* @param [T] class that defines target schema for conversion.
* @param [schemaFrom] dataframe which type [T] will be used.
* @param [excessiveColumnsBehavior] how to handle excessive columns in the original [DataFrame].
* @param [body] optional dsl to define custom type converters.
* @throws [ColumnNotFoundException] if [DataFrame] doesn't contain columns that are required by destination schema.
* @throws [ExcessiveColumnsException] if [DataFrame] contains columns that are not required by destination schema and [excessiveColumnsBehavior] is set to [ExcessiveColumns.Fail].
* @throws [TypeConverterNotFoundException] if suitable type converter for some column was not found.
* @throws [TypeConversionException] if type converter failed to convert column values.
* @return converted [DataFrame].
*/
public inline fun <reified T : Any> AnyFrame.convertTo(
@Suppress("UNUSED_PARAMETER") schemaFrom: DataFrame<T>,
excessiveColumnsBehavior: ExcessiveColumns = ExcessiveColumns.Keep,
noinline body: ConvertSchemaDsl<T>.() -> Unit = {}
): DataFrame<T> = convertToImpl(typeOf<T>(), true, excessiveColumnsBehavior, body).cast()

/**
* Converts values in [DataFrame] to match given column schema [schemaType].
*
Expand Down