Skip to content

Commit 2daaa41

Browse files
committed
Fixes std() not inferring column types by adding an aggregator for mergedValuesChangingTypes().
1 parent 2c4fdfc commit 2daaa41

File tree

4 files changed

+12
-2
lines changed
  • core
    • generated-sources/src
      • main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/aggregators
      • test/kotlin/org/jetbrains/kotlinx/dataframe/statistics
    • src
      • main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/aggregators
      • test/kotlin/org/jetbrains/kotlinx/dataframe/statistics

4 files changed

+12
-2
lines changed

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/aggregators/Aggregators.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ internal object Aggregators {
1616
private fun <C : Any, R> mergedValues(aggregate: Iterable<C?>.(KType) -> R?) =
1717
MergedValuesAggregator.Factory(aggregate, true)
1818

19+
private fun <C : Any, R> mergedValuesChangingTypes(aggregate: Iterable<C?>.(KType) -> R?) =
20+
MergedValuesAggregator.Factory(aggregate, false)
21+
1922
private fun <C, R> changesType(aggregate1: Iterable<C>.(KType) -> R, aggregate2: Iterable<R>.(KType) -> R) =
2023
TwoStepAggregator.Factory(aggregate1, aggregate2, false)
2124

@@ -33,7 +36,7 @@ internal object Aggregators {
3336
val max by preservesType<Comparable<Any?>> { maxOrNull() }
3437

3538
val std by withOption2<Boolean, Int, Number, Double> { skipNA, ddof ->
36-
mergedValues { std(it, skipNA, ddof) }
39+
mergedValuesChangingTypes { std(it, skipNA, ddof) }
3740
}
3841

3942
val mean by withOption<Boolean, Number, Double> { skipNA ->

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/statistics/std.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.jetbrains.kotlinx.dataframe.statistics
22

33
import io.kotest.matchers.shouldBe
44
import org.jetbrains.kotlinx.dataframe.api.columnOf
5+
import org.jetbrains.kotlinx.dataframe.api.columnTypes
56
import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
67
import org.jetbrains.kotlinx.dataframe.api.std
78
import org.jetbrains.kotlinx.dataframe.math.std
@@ -21,6 +22,7 @@ class StdTests {
2122
value.std() shouldBe expected
2223
df[value].std() shouldBe expected
2324
df.std { value } shouldBe expected
25+
df.std().columnTypes().single() shouldBe typeOf<Double>()
2426
}
2527

2628
@Test

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ internal object Aggregators {
1616
private fun <C : Any, R> mergedValues(aggregate: Iterable<C?>.(KType) -> R?) =
1717
MergedValuesAggregator.Factory(aggregate, true)
1818

19+
private fun <C : Any, R> mergedValuesChangingTypes(aggregate: Iterable<C?>.(KType) -> R?) =
20+
MergedValuesAggregator.Factory(aggregate, false)
21+
1922
private fun <C, R> changesType(aggregate1: Iterable<C>.(KType) -> R, aggregate2: Iterable<R>.(KType) -> R) =
2023
TwoStepAggregator.Factory(aggregate1, aggregate2, false)
2124

@@ -33,7 +36,7 @@ internal object Aggregators {
3336
val max by preservesType<Comparable<Any?>> { maxOrNull() }
3437

3538
val std by withOption2<Boolean, Int, Number, Double> { skipNA, ddof ->
36-
mergedValues { std(it, skipNA, ddof) }
39+
mergedValuesChangingTypes { std(it, skipNA, ddof) }
3740
}
3841

3942
val mean by withOption<Boolean, Number, Double> { skipNA ->

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/statistics/std.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.jetbrains.kotlinx.dataframe.statistics
22

33
import io.kotest.matchers.shouldBe
44
import org.jetbrains.kotlinx.dataframe.api.columnOf
5+
import org.jetbrains.kotlinx.dataframe.api.columnTypes
56
import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
67
import org.jetbrains.kotlinx.dataframe.api.std
78
import org.jetbrains.kotlinx.dataframe.math.std
@@ -21,6 +22,7 @@ class StdTests {
2122
value.std() shouldBe expected
2223
df[value].std() shouldBe expected
2324
df.std { value } shouldBe expected
25+
df.std().columnTypes().single() shouldBe typeOf<Double>()
2426
}
2527

2628
@Test

0 commit comments

Comments
 (0)