From cd3747fa5cc2831d4050a74e0dd0a2c3e04e7609 Mon Sep 17 00:00:00 2001 From: Jolan Rensen Date: Tue, 30 Jul 2024 17:00:13 +0200 Subject: [PATCH 1/3] small QoL improvement to the value/type check of DataColumnImpl --- .../jetbrains/kotlinx/dataframe/impl/columns/DataColumnImpl.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/columns/DataColumnImpl.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/columns/DataColumnImpl.kt index aef3f08b83..eac43db02b 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/columns/DataColumnImpl.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/columns/DataColumnImpl.kt @@ -5,6 +5,7 @@ import org.jetbrains.kotlinx.dataframe.DataColumn import org.jetbrains.kotlinx.dataframe.api.dataFrameOf import org.jetbrains.kotlinx.dataframe.impl.isArray import org.jetbrains.kotlinx.dataframe.impl.isPrimitiveArray +import org.jetbrains.kotlinx.dataframe.kind import kotlin.reflect.KClass import kotlin.reflect.KType import kotlin.reflect.full.isSubclassOf @@ -37,7 +38,7 @@ internal abstract class DataColumnImpl( if (BuildConfig.DEBUG) { require(values.all { it matches type }) { val types = values.map { if (it == null) "Nothing?" else it!!::class.simpleName }.distinct() - "Values of column '$name' have types '$types' which are not compatible given with column type '$type'" + "Values of $kind '$name' have types '$types' which are not compatible given with column type '$type'" } } } From 3037a978d13f211401bec79e8ae17fa99a658cf0 Mon Sep 17 00:00:00 2001 From: Jolan Rensen Date: Tue, 30 Jul 2024 17:01:34 +0200 Subject: [PATCH 2/3] small fix for two failing tests in #713, where in implodeImpl a temporary column was created with nulls in a FrameColumn --- .../jetbrains/kotlinx/dataframe/impl/api/implode.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/implode.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/implode.kt index 84b2446d7b..988f7bc3b9 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/implode.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/implode.kt @@ -30,8 +30,14 @@ internal fun DataFrame.implodeImpl(dropNA: Boolean = false, columns: C first = false value } else { - null + // these rows will not be taken into account, + // but we cannot leave them empty, as `map` creates a full column + when (column.kind()) { + ColumnKind.Value -> emptyList() + ColumnKind.Group -> DataFrame.empty() + ColumnKind.Frame -> emptyList() + } } } - }[0..0] + }[0..0] // takes only the first row }.concat() From 23046d82fbf28a355d6e916cd343e780b86b835f Mon Sep 17 00:00:00 2001 From: Jolan Rensen Date: Wed, 31 Jul 2024 14:31:07 +0200 Subject: [PATCH 3/3] small fix for one failing test in #713, where GroupBy.aggregate { this into "" } would break typing --- .../impl/aggregation/GroupByReceiverImpl.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/GroupByReceiverImpl.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/GroupByReceiverImpl.kt index 171403c4f8..5272accd19 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/GroupByReceiverImpl.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/GroupByReceiverImpl.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlinx.dataframe.columns.ValueColumn import org.jetbrains.kotlinx.dataframe.columns.shortPath import org.jetbrains.kotlinx.dataframe.impl.aggregation.receivers.AggregateInternalDsl import org.jetbrains.kotlinx.dataframe.impl.api.AggregatedPivot +import org.jetbrains.kotlinx.dataframe.impl.createStarProjectedType import org.jetbrains.kotlinx.dataframe.impl.createTypeWithArgument import org.jetbrains.kotlinx.dataframe.impl.getListType import kotlin.reflect.KType @@ -118,7 +119,19 @@ internal class GroupByReceiverImpl(override val df: DataFrame, override va pivot.aggregator.values.clear() } - is AggregateInternalDsl<*> -> yield(value.copy(value = value.value.df)) + is AggregateInternalDsl<*> -> { + // Attempt to create DataFrame from AggregateInternalDsl + val dfType = value.type?.arguments?.firstOrNull()?.type + ?.let { DataFrame::class.createTypeWithArgument(it) } + ?: DataFrame::class.createStarProjectedType(nullable = false) + + yield( + value.copy( + value = value.value.df, + type = dfType, + ), + ) + } else -> values.add(value) }