Skip to content

Fixes std() not inferring column types #728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ internal object Aggregators {
private fun <C : Any, R> mergedValues(aggregate: Iterable<C?>.(KType) -> R?) =
MergedValuesAggregator.Factory(aggregate, true)

private fun <C : Any, R> mergedValuesChangingTypes(aggregate: Iterable<C?>.(KType) -> R?) =
MergedValuesAggregator.Factory(aggregate, false)

private fun <C, R> changesType(aggregate1: Iterable<C>.(KType) -> R, aggregate2: Iterable<R>.(KType) -> R) =
TwoStepAggregator.Factory(aggregate1, aggregate2, false)

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

val std by withOption2<Boolean, Int, Number, Double> { skipNA, ddof ->
mergedValues { std(it, skipNA, ddof) }
mergedValuesChangingTypes { std(it, skipNA, ddof) }
}

val mean by withOption<Boolean, Number, Double> { skipNA ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.jetbrains.kotlinx.dataframe.statistics

import io.kotest.matchers.shouldBe
import org.jetbrains.kotlinx.dataframe.api.columnOf
import org.jetbrains.kotlinx.dataframe.api.columnTypes
import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
import org.jetbrains.kotlinx.dataframe.api.std
import org.jetbrains.kotlinx.dataframe.math.std
Expand All @@ -21,6 +22,7 @@ class StdTests {
value.std() shouldBe expected
df[value].std() shouldBe expected
df.std { value } shouldBe expected
df.std().columnTypes().single() shouldBe typeOf<Double>()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ internal object Aggregators {
private fun <C : Any, R> mergedValues(aggregate: Iterable<C?>.(KType) -> R?) =
MergedValuesAggregator.Factory(aggregate, true)

private fun <C : Any, R> mergedValuesChangingTypes(aggregate: Iterable<C?>.(KType) -> R?) =
MergedValuesAggregator.Factory(aggregate, false)

private fun <C, R> changesType(aggregate1: Iterable<C>.(KType) -> R, aggregate2: Iterable<R>.(KType) -> R) =
TwoStepAggregator.Factory(aggregate1, aggregate2, false)

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

val std by withOption2<Boolean, Int, Number, Double> { skipNA, ddof ->
mergedValues { std(it, skipNA, ddof) }
mergedValuesChangingTypes { std(it, skipNA, ddof) }
}

val mean by withOption<Boolean, Number, Double> { skipNA ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.jetbrains.kotlinx.dataframe.statistics

import io.kotest.matchers.shouldBe
import org.jetbrains.kotlinx.dataframe.api.columnOf
import org.jetbrains.kotlinx.dataframe.api.columnTypes
import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
import org.jetbrains.kotlinx.dataframe.api.std
import org.jetbrains.kotlinx.dataframe.math.std
Expand All @@ -21,6 +22,7 @@ class StdTests {
value.std() shouldBe expected
df[value].std() shouldBe expected
df.std { value } shouldBe expected
df.std().columnTypes().single() shouldBe typeOf<Double>()
}

@Test
Expand Down