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