Skip to content

Commit 12d0922

Browse files
committed
added tests and fixed NaN behavior for min/max functions
1 parent 87ab8ed commit 12d0922

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2471
-1558
lines changed

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/DataColumnType.kt

+2-14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
77
import org.jetbrains.kotlinx.dataframe.columns.ColumnKind
88
import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
99
import org.jetbrains.kotlinx.dataframe.columns.ValueColumn
10+
import org.jetbrains.kotlinx.dataframe.impl.isIntraComparable
1011
import org.jetbrains.kotlinx.dataframe.impl.isMixedNumber
1112
import org.jetbrains.kotlinx.dataframe.impl.isPrimitiveNumber
1213
import org.jetbrains.kotlinx.dataframe.impl.isPrimitiveOrMixedNumber
@@ -18,11 +19,7 @@ import org.jetbrains.kotlinx.dataframe.util.IS_INTER_COMPARABLE_IMPORT
1819
import kotlin.contracts.ExperimentalContracts
1920
import kotlin.contracts.contract
2021
import kotlin.reflect.KType
21-
import kotlin.reflect.KTypeProjection
22-
import kotlin.reflect.KVariance
23-
import kotlin.reflect.full.createType
2422
import kotlin.reflect.full.isSubtypeOf
25-
import kotlin.reflect.full.withNullability
2623
import kotlin.reflect.typeOf
2724

2825
public fun AnyCol.isColumnGroup(): Boolean {
@@ -93,13 +90,4 @@ public fun AnyCol.isComparable(): Boolean = valuesAreComparable()
9390
*
9491
* Technically, this means the values' common type `T(?)` is a subtype of [Comparable]`<in T>(?)`
9592
*/
96-
public fun AnyCol.valuesAreComparable(): Boolean =
97-
isValueColumn() &&
98-
isSubtypeOf(
99-
Comparable::class.createType(
100-
arguments = listOf(
101-
KTypeProjection(KVariance.IN, type().withNullability(false)),
102-
),
103-
nullable = hasNulls(),
104-
),
105-
)
93+
public fun AnyCol.valuesAreComparable(): Boolean = isValueColumn() && type().isIntraComparable()
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.jetbrains.kotlinx.dataframe.api
22

33
@PublishedApi
4-
internal val skipNA_default: Boolean = false
4+
internal val skipNaN_default: Boolean = false
55

66
@PublishedApi
77
internal val ddof_default: Int = 1

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/Nulls.kt

+10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import org.jetbrains.kotlinx.dataframe.documentation.NaN
1818
import org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns
1919
import org.jetbrains.kotlinx.dataframe.get
2020
import org.jetbrains.kotlinx.dataframe.typeClass
21+
import kotlin.contracts.ExperimentalContracts
22+
import kotlin.contracts.contract
2123
import kotlin.reflect.KProperty
2224

2325
// region fillNulls
@@ -300,6 +302,14 @@ public fun <T, C> DataFrame<T>.fillNulls(vararg columns: ColumnReference<C>): Up
300302

301303
internal inline val Any?.isNaN: Boolean get() = (this is Double && isNaN()) || (this is Float && isNaN())
302304

305+
@JvmName("isNaWithContract")
306+
@Suppress("NOTHING_TO_INLINE")
307+
@OptIn(ExperimentalContracts::class)
308+
internal inline fun <T : Any?> T.isNA(): Boolean {
309+
contract { returns(false) implies (this@isNA != null) }
310+
return isNA
311+
}
312+
303313
internal inline val Any?.isNA: Boolean
304314
get() = when (this) {
305315
null -> true

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/groupBy.kt

+1
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,5 @@ public class ReducedGroupBy<T, G>(
109109
override fun toString(): String = "ReducedGroupBy(groupBy=$groupBy, reducer=$reducer)"
110110
}
111111

112+
@PublishedApi
112113
internal fun <T, G> GroupBy<T, G>.reduce(reducer: Selector<DataFrame<G>, DataRow<G>?>) = ReducedGroupBy(this, reducer)

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/max.kt

+271-143
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)