Skip to content

Commit cb374a4

Browse files
committed
small fix for one failing test in #713, where GroupBy.aggregate { this into "" } would break typing
1 parent 3037a97 commit cb374a4

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/GroupByReceiverImpl.kt

+14-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import org.jetbrains.kotlinx.dataframe.DataFrame
66
import org.jetbrains.kotlinx.dataframe.aggregation.AggregateGroupedDsl
77
import org.jetbrains.kotlinx.dataframe.aggregation.NamedValue
88
import org.jetbrains.kotlinx.dataframe.api.asDataFrame
9+
import org.jetbrains.kotlinx.dataframe.api.cast
10+
import org.jetbrains.kotlinx.dataframe.api.convertTo
911
import org.jetbrains.kotlinx.dataframe.api.toDataFrameFromPairs
1012
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
1113
import org.jetbrains.kotlinx.dataframe.columns.ColumnPath
@@ -118,7 +120,18 @@ internal class GroupByReceiverImpl<T>(override val df: DataFrame<T>, override va
118120
pivot.aggregator.values.clear()
119121
}
120122

121-
is AggregateInternalDsl<*> -> yield(value.copy(value = value.value.df))
123+
is AggregateInternalDsl<*> -> {
124+
// Attempt to create DataFrame<Type> from AggregateInternalDsl<Type>
125+
val dfType = value.type?.arguments?.firstOrNull()?.type?.let {
126+
DataFrame::class.createTypeWithArgument(it)
127+
}
128+
yield(
129+
value.copy(
130+
value = value.value.df,
131+
type = dfType ?: value.type,
132+
),
133+
)
134+
}
122135

123136
else -> values.add(value)
124137
}

0 commit comments

Comments
 (0)