Skip to content

Commit 87165ba

Browse files
committed
added back support for Nothing in TwoStepNumbersAggregator
1 parent f922d9f commit 87165ba

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.jetbrains.kotlinx.dataframe.DataColumn
55
import org.jetbrains.kotlinx.dataframe.documentation.UnifyingNumbers
66
import org.jetbrains.kotlinx.dataframe.impl.UnifiedNumberTypeOptions.Companion.PRIMITIVES_ONLY
77
import org.jetbrains.kotlinx.dataframe.impl.convertToUnifiedNumberType
8+
import org.jetbrains.kotlinx.dataframe.impl.nothingType
89
import org.jetbrains.kotlinx.dataframe.impl.primitiveNumberTypes
910
import org.jetbrains.kotlinx.dataframe.impl.renderType
1011
import org.jetbrains.kotlinx.dataframe.impl.types
@@ -93,12 +94,15 @@ internal class TwoStepNumbersAggregator<out Return : Number>(
9394
"${TwoStepNumbersAggregator::class.simpleName}: Type $type is not a subtype of Number?"
9495
}
9596

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
9997
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
100101
typeOf<Number>() -> aggregateCalculatingType(values)
101102

103+
// Nothing can occur when values are empty
104+
nothingType -> super.aggregate(values, type)
105+
102106
!in primitiveNumberTypes -> throw IllegalArgumentException(
103107
"Cannot calculate $name of ${renderType(type)}, only primitive numbers are supported.",
104108
)
@@ -130,7 +134,7 @@ internal class TwoStepNumbersAggregator<out Return : Number>(
130134
"Number unification of Long -> Double happened during aggregation. Loss of precision may have occurred."
131135
}
132136
}
133-
if (commonType !in primitiveNumberTypes) {
137+
if (commonType !in primitiveNumberTypes && commonType != nothingType) {
134138
throw IllegalArgumentException(
135139
"Cannot calculate $name of ${renderType(commonType)}, only primitive numbers are supported.",
136140
)

0 commit comments

Comments
 (0)