From 3cb943847c13cbd409993376774d6fe86246408c Mon Sep 17 00:00:00 2001 From: Jolan Rensen Date: Fri, 8 Nov 2024 13:30:19 +0100 Subject: [PATCH] fixed parseImpl removing unselected columns by reverting implementation to use `convert` instead of `insert` --- .../kotlinx/dataframe/impl/api/parse.kt | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/parse.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/parse.kt index 99b4ec7ca..541b61409 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/parse.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/parse.kt @@ -20,12 +20,13 @@ import org.jetbrains.kotlinx.dataframe.api.ParserOptions import org.jetbrains.kotlinx.dataframe.api.asColumnGroup import org.jetbrains.kotlinx.dataframe.api.asDataColumn import org.jetbrains.kotlinx.dataframe.api.cast -import org.jetbrains.kotlinx.dataframe.api.emptyDataFrame -import org.jetbrains.kotlinx.dataframe.api.getColumnsWithPaths +import org.jetbrains.kotlinx.dataframe.api.convert import org.jetbrains.kotlinx.dataframe.api.isColumnGroup import org.jetbrains.kotlinx.dataframe.api.isFrameColumn import org.jetbrains.kotlinx.dataframe.api.isSubtypeOf -import org.jetbrains.kotlinx.dataframe.api.toColumn +import org.jetbrains.kotlinx.dataframe.api.map +import org.jetbrains.kotlinx.dataframe.api.parse +import org.jetbrains.kotlinx.dataframe.api.to import org.jetbrains.kotlinx.dataframe.api.tryParse import org.jetbrains.kotlinx.dataframe.columns.TypeSuggestion import org.jetbrains.kotlinx.dataframe.columns.size @@ -531,17 +532,16 @@ internal fun DataColumn.parse(parser: StringParser, options: Par ) } -internal fun DataFrame.parseImpl(options: ParserOptions?, columns: ColumnsSelector): DataFrame { - val convertedCols = getColumnsWithPaths(columns).map { col -> +internal fun DataFrame.parseImpl(options: ParserOptions?, columns: ColumnsSelector): DataFrame = + convert(columns).to { col -> when { // when a frame column is requested to be parsed, // parse each value/frame column at any depth inside each DataFrame in the frame column - col.isFrameColumn() -> - col.values.map { - it.parseImpl(options) { - colsAtAnyDepth { !it.isColumnGroup() } - } - }.toColumn(col.name) + col.isFrameColumn() -> col.map { + it.parseImpl(options) { + colsAtAnyDepth { !it.isColumnGroup() } + } + } // when a column group is requested to be parsed, // parse each column in the group @@ -552,11 +552,8 @@ internal fun DataFrame.parseImpl(options: ParserOptions?, columns: Column // Base case, parse the column if it's a `String?` column col.isSubtypeOf() -> - col.cast().tryParse(options) + col.cast().tryParseImpl(options) else -> col - }.let { ColumnToInsert(col.path, it) } + } } - - return emptyDataFrame().insertImpl(convertedCols) -}