convertTo

inline fun <reified C> DataColumn<*>.convertTo(): DataColumn<C>

Converts values in this column to the specified type C.

The target type is provided as a reified type argument.

For the full list of supported types, see SupportedTypes.

For more information: See convert on the documentation website.

Return

A new DataColumn with the values converted to type C.

Type Parameters

C

The target type to convert values to.


fun DataColumn<*>.convertTo(newType: KType): DataColumn<*>

Converts values in this column to the specified type.

For the full list of supported types, see SupportedTypes.

For more information: See convert on the documentation website.

Return

A new DataColumn with the values converted to type.

Parameters

newType

The target type, provided as a KType, to convert values to.


inline fun <reified C> DataColumn<String?>.convertTo(parserOptions: ParserOptions? = null): DataColumn<C>

Converts values in this String column to the specified type C.

The target type is provided as a reified type argument.

See also parse — a specialized form of the convert operation that parses String columns into other types without requiring explicit type specification.

For more information: See convert on the documentation website.

Return

A new DataColumn with the values converted to type C.

Parameters

parserOptions

Optional ParserOptions to customize parsing behavior (e.g., locale, null strings).

Type Parameters

C

The target type to convert values to.


fun DataColumn<String?>.convertTo(newType: KType, parserOptions: ParserOptions? = null): DataColumn<*>

Converts values in this String column to the specified type.

The target type is provided as a KType.

See also parse — a specialized form of the convert operation that parses String columns into other types without requiring explicit type specification.

For more information: See convert on the documentation website.

Return

A new DataColumn with the values converted to type.

Parameters

newType

The target type to convert values to.

parserOptions

Optional ParserOptions to customize parsing behavior (e.g., locale, null strings).


inline fun <reified T : Any> DataFrame<*>.convertTo(excessiveColumnsBehavior: ExcessiveColumns = ExcessiveColumns.Keep, noinline body: ConvertSchemaDsl<T>.() -> Unit = {}): DataFrame<T>

Converts values in DataFrame to match given column schema T.

Original columns are mapped to destination columns by column 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.

For more information: See convertTo on the documentation website.

Example of Dsl:

df.convertTo<SomeSchema> {
// 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 }
}

Return

converted DataFrame.

Parameters

excessiveColumnsBehavior

how to handle excessive columns in the original DataFrame.

body

optional dsl to define custom type converters.

Type Parameters

T

class that defines target schema for conversion.

Throws

if DataFrame doesn't contain columns that are required by destination schema.

if DataFrame contains columns that are not required by destination schema and excessiveColumnsBehavior is set to ExcessiveColumns.Fail.

if suitable type converter for some column was not found.

if type converter failed to convert column values.


inline fun <reified T : Any> DataFrame<*>.convertTo(schemaFrom: DataFrame<T>, excessiveColumnsBehavior: ExcessiveColumns = ExcessiveColumns.Keep, noinline body: ConvertSchemaDsl<T>.() -> Unit = {}): DataFrame<T>

Converts values in DataFrame to match given column schema T.

Original columns are mapped to destination columns by column 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.

For more information: See convertTo on the documentation website.

Example of Dsl:

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 }
}

Return

converted DataFrame.

Parameters

schemaFrom

dataframe which type T will be used.

excessiveColumnsBehavior

how to handle excessive columns in the original DataFrame.

body

optional dsl to define custom type converters.

Type Parameters

T

class that defines target schema for conversion.

Throws

if DataFrame doesn't contain columns that are required by destination schema.

if DataFrame contains columns that are not required by destination schema and excessiveColumnsBehavior is set to ExcessiveColumns.Fail.

if suitable type converter for some column was not found.

if type converter failed to convert column values.


fun DataFrame<*>.convertTo(schemaType: KType, excessiveColumnsBehavior: ExcessiveColumns = ExcessiveColumns.Keep, body: ConvertSchemaDsl<Any>.() -> Unit = {}): DataFrame<*>

Converts values in DataFrame to match given column schema schemaType.

Original columns are mapped to destination columns by column 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.

For more information: See convertTo on the documentation website.

Example of Dsl:

df.convertTo<SomeSchema> {
// 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 }
}

Return

converted DataFrame.

Parameters

schemaType

defines target schema for conversion.

excessiveColumnsBehavior

how to handle excessive columns in the original DataFrame.

body

optional dsl to define custom type converters.

Throws

if DataFrame doesn't contain columns that are required by destination schema.

if DataFrame contains columns that are not required by destination schema and excessiveColumnsBehavior is set to ExcessiveColumns.Fail.

if suitable type converter for some column was not found.

if type converter failed to convert column values.