Open
Description
In our application, we use the dataframe library to parse CSV and preprocess it before we transform the rows into our internal domain objects. This works really well and feels quite natural (coming from spark, pandas, polars, ...).
However, for large datasets, working with eagerly created collections sometimes seems wasteful, as we sometimes immediately chain other mappings or filters - i.e. we discard the List that gets returned from DataFrame.toListOf.
AFAIK it would be way more memory efficient to use a asSequenceOf in those scenarios.
Looking at the implementation of toListOf()
:
// org/jetbrains/kotlinx/dataframe/api/toList.kt
public inline fun <reified T> AnyFrame.toListOf(): List<T> = toListImpl(typeOf<T>()) as List<T>
and
// org/jetbrains/kotlinx/dataframe/impl/api/toList.kt
internal fun AnyFrame.toListImpl(type: KType): List<Any> {
....
return rows().map { row ->
val parameters = convertedColumns
.map { row[it] }
.toTypedArray()
constructor.call(*parameters)
}
}
and
// org/jetbrains/kotlinx/dataframe/api/DataFrameGet.kt
public fun <T> DataFrame<T>.rows(): Iterable<DataRow<T>> = ...
It looks like a asSequenceOf()
method could trivially be added?