@@ -5,6 +5,7 @@ import org.jetbrains.kotlinx.dataframe.DataColumn
5
5
import org.jetbrains.kotlinx.dataframe.documentation.UnifyingNumbers
6
6
import org.jetbrains.kotlinx.dataframe.impl.UnifiedNumberTypeOptions.Companion.PRIMITIVES_ONLY
7
7
import org.jetbrains.kotlinx.dataframe.impl.convertToUnifiedNumberType
8
+ import org.jetbrains.kotlinx.dataframe.impl.nothingType
8
9
import org.jetbrains.kotlinx.dataframe.impl.primitiveNumberTypes
9
10
import org.jetbrains.kotlinx.dataframe.impl.renderType
10
11
import org.jetbrains.kotlinx.dataframe.impl.types
@@ -93,12 +94,15 @@ internal class TwoStepNumbersAggregator<out Return : Number>(
93
94
" ${TwoStepNumbersAggregator ::class .simpleName} : Type $type is not a subtype of Number?"
94
95
}
95
96
96
- // If the type is not a specific number, but rather a mixed Number, we unify the types first.
97
- // This is heavy and could be avoided by calling aggregate with a specific number type
98
- // or calling aggregateCalculatingType with all known number types
99
97
return when (type.withNullability(false )) {
98
+ // If the type is not a specific number, but rather a mixed Number, we unify the types first.
99
+ // This is heavy and could be avoided by calling aggregate with a specific number type
100
+ // or calling aggregateCalculatingType with all known number types
100
101
typeOf<Number >() -> aggregateCalculatingType(values)
101
102
103
+ // Nothing can occur when values are empty
104
+ nothingType -> super .aggregate(values, type)
105
+
102
106
!in primitiveNumberTypes -> throw IllegalArgumentException (
103
107
" Cannot calculate $name of ${renderType(type)} , only primitive numbers are supported." ,
104
108
)
@@ -130,7 +134,7 @@ internal class TwoStepNumbersAggregator<out Return : Number>(
130
134
" Number unification of Long -> Double happened during aggregation. Loss of precision may have occurred."
131
135
}
132
136
}
133
- if (commonType !in primitiveNumberTypes) {
137
+ if (commonType !in primitiveNumberTypes && commonType != nothingType ) {
134
138
throw IllegalArgumentException (
135
139
" Cannot calculate $name of ${renderType(commonType)} , only primitive numbers are supported." ,
136
140
)
0 commit comments