diff --git a/core/api/core.api b/core/api/core.api index 9711065442..f281641220 100644 --- a/core/api/core.api +++ b/core/api/core.api @@ -4150,12 +4150,12 @@ public final class org/jetbrains/kotlinx/dataframe/api/DataColumnTypeKt { public static final fun isColumnGroup (Lorg/jetbrains/kotlinx/dataframe/DataColumn;)Z public static final fun isComparable (Lorg/jetbrains/kotlinx/dataframe/DataColumn;)Z public static final fun isFrameColumn (Lorg/jetbrains/kotlinx/dataframe/DataColumn;)Z - public static final fun isInterComparable (Lorg/jetbrains/kotlinx/dataframe/DataColumn;)Z public static final fun isList (Lorg/jetbrains/kotlinx/dataframe/DataColumn;)Z public static final fun isNumber (Lorg/jetbrains/kotlinx/dataframe/DataColumn;)Z public static final fun isPrimitive (Lorg/jetbrains/kotlinx/dataframe/DataColumn;)Z public static final fun isSubtypeOf (Lorg/jetbrains/kotlinx/dataframe/DataColumn;Lkotlin/reflect/KType;)Z public static final fun isValueColumn (Lorg/jetbrains/kotlinx/dataframe/DataColumn;)Z + public static final fun valuesAreComparable (Lorg/jetbrains/kotlinx/dataframe/DataColumn;)Z } public final class org/jetbrains/kotlinx/dataframe/api/DataFrameBuilder { diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/DataColumnType.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/DataColumnType.kt index 9c360cbc32..86189a585a 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/DataColumnType.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/DataColumnType.kt @@ -53,22 +53,22 @@ public fun AnyCol.isBigNumber(): Boolean = isSubtypeOf() || isSubty public fun AnyCol.isList(): Boolean = typeClass == List::class -/** @include [isInterComparable] */ +/** @include [valuesAreComparable] */ @Deprecated( message = IS_COMPARABLE, replaceWith = ReplaceWith(IS_COMPARABLE_REPLACE, IS_INTER_COMPARABLE_IMPORT), level = DeprecationLevel.WARNING, ) -public fun AnyCol.isComparable(): Boolean = isInterComparable() +public fun AnyCol.isComparable(): Boolean = valuesAreComparable() /** * Returns `true` if [this] column is inter-comparable, i.e. - * its elements can be compared with each other. + * its values can be compared with each other. * - * Technically, this means the elements' common type is a subtype of [Comparable] with + * Technically, this means the values' common type is a subtype of [Comparable] with * the type argument not being [Nothing]. */ -public fun AnyCol.isInterComparable(): Boolean = +public fun AnyCol.valuesAreComparable(): Boolean = isSubtypeOf?>() && type().projectTo(Comparable::class).arguments[0].let { it != KTypeProjection.STAR && diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/typeConversions.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/typeConversions.kt index adafce95cd..163ff395ea 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/typeConversions.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/typeConversions.kt @@ -83,7 +83,7 @@ public fun DataColumn.asNumbers(): ValueColumn { } public fun DataColumn.asComparable(): DataColumn> { - require(isInterComparable()) + require(valuesAreComparable()) return this as DataColumn> } diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/getColumns.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/getColumns.kt index 60c7104e24..6f514d95eb 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/getColumns.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/getColumns.kt @@ -5,8 +5,8 @@ import org.jetbrains.kotlinx.dataframe.ColumnsSelector import org.jetbrains.kotlinx.dataframe.aggregation.Aggregatable import org.jetbrains.kotlinx.dataframe.aggregation.NamedValue import org.jetbrains.kotlinx.dataframe.api.filter -import org.jetbrains.kotlinx.dataframe.api.isInterComparable import org.jetbrains.kotlinx.dataframe.api.isNumber +import org.jetbrains.kotlinx.dataframe.api.valuesAreComparable import org.jetbrains.kotlinx.dataframe.columns.TypeSuggestion import org.jetbrains.kotlinx.dataframe.impl.columns.createColumnGuessingType @@ -15,7 +15,7 @@ internal inline fun Aggregatable.remainingColumns( ): ColumnsSelector = remainingColumnsSelector().filter { predicate(it.data) } internal fun Aggregatable.interComparableColumns() = - remainingColumns { it.isInterComparable() } as ColumnsSelector> + remainingColumns { it.valuesAreComparable() } as ColumnsSelector> internal fun Aggregatable.numberColumns() = remainingColumns { it.isNumber() } as ColumnsSelector diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/describe.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/describe.kt index c2929ed08a..109b031587 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/describe.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/describe.kt @@ -12,7 +12,6 @@ import org.jetbrains.kotlinx.dataframe.api.asComparable import org.jetbrains.kotlinx.dataframe.api.asNumbers import org.jetbrains.kotlinx.dataframe.api.cast import org.jetbrains.kotlinx.dataframe.api.concat -import org.jetbrains.kotlinx.dataframe.api.isInterComparable import org.jetbrains.kotlinx.dataframe.api.isNumber import org.jetbrains.kotlinx.dataframe.api.map import org.jetbrains.kotlinx.dataframe.api.maxOrNull @@ -23,6 +22,7 @@ import org.jetbrains.kotlinx.dataframe.api.move import org.jetbrains.kotlinx.dataframe.api.name import org.jetbrains.kotlinx.dataframe.api.std import org.jetbrains.kotlinx.dataframe.api.toDataFrame +import org.jetbrains.kotlinx.dataframe.api.valuesAreComparable import org.jetbrains.kotlinx.dataframe.columns.ColumnKind import org.jetbrains.kotlinx.dataframe.columns.size import org.jetbrains.kotlinx.dataframe.columns.values @@ -39,7 +39,7 @@ internal fun describeImpl(cols: List): DataFrame { val allCols = cols.collectAll(false) val hasNumericCols = allCols.any { it.isNumber() } - val hasInterComparableCols = allCols.any { it.isInterComparable() } + val hasComparableCols = allCols.any { it.valuesAreComparable() } val hasLongPaths = allCols.any { it.path().size > 1 } var df = allCols.toDataFrame { ColumnDescription::name from { it.name() } @@ -59,15 +59,15 @@ internal fun describeImpl(cols: List): DataFrame { ColumnDescription::mean from { if (it.isNumber()) it.asNumbers().mean() else null } ColumnDescription::std from { if (it.isNumber()) it.asNumbers().std() else null } } - if (hasInterComparableCols || hasNumericCols) { + if (hasComparableCols || hasNumericCols) { ColumnDescription::min from inferType { - it.convertToInterComparableOrNull()?.minOrNull() + it.convertToComparableOrNull()?.minOrNull() } ColumnDescription::median from inferType { - it.convertToInterComparableOrNull()?.medianOrNull() + it.convertToComparableOrNull()?.medianOrNull() } ColumnDescription::max from inferType { - it.convertToInterComparableOrNull()?.maxOrNull() + it.convertToComparableOrNull()?.maxOrNull() } } } @@ -105,9 +105,9 @@ private fun List.collectAll(atAnyDepth: Boolean): List = } /** Converts a column to a comparable column if it is not already comparable. */ -private fun DataColumn.convertToInterComparableOrNull(): DataColumn>? = +private fun DataColumn.convertToComparableOrNull(): DataColumn>? = when { - isInterComparable() -> asComparable() + valuesAreComparable() -> asComparable() // Found incomparable number types, convert all to Double or BigDecimal first isNumber() -> diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/KotlinNotebookPluginUtils.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/KotlinNotebookPluginUtils.kt index 382e60fedd..730b3234aa 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/KotlinNotebookPluginUtils.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/KotlinNotebookPluginUtils.kt @@ -28,10 +28,10 @@ import org.jetbrains.kotlinx.dataframe.api.dataFrameOf import org.jetbrains.kotlinx.dataframe.api.frames import org.jetbrains.kotlinx.dataframe.api.getColumn import org.jetbrains.kotlinx.dataframe.api.into -import org.jetbrains.kotlinx.dataframe.api.isInterComparable import org.jetbrains.kotlinx.dataframe.api.sortWith import org.jetbrains.kotlinx.dataframe.api.toDataFrame import org.jetbrains.kotlinx.dataframe.api.values +import org.jetbrains.kotlinx.dataframe.api.valuesAreComparable import org.jetbrains.kotlinx.dataframe.columns.ColumnPath import org.jetbrains.kotlinx.dataframe.impl.ColumnNameGenerator @@ -107,7 +107,7 @@ public object KotlinNotebookPluginUtils { private fun createComparator(sortKeys: List, isDesc: List): Comparator> { return Comparator { row1, row2 -> for ((key, desc) in sortKeys.zip(isDesc)) { - val comparisonResult = if (row1.df().getColumn(key).isInterComparable()) { + val comparisonResult = if (row1.df().getColumn(key).valuesAreComparable()) { compareComparableValues(row1, row2, key, desc) } else { compareStringValues(row1, row2, key, desc) diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/util/deprecationMessages.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/util/deprecationMessages.kt index 49406e269d..237f7041b6 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/util/deprecationMessages.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/util/deprecationMessages.kt @@ -45,9 +45,9 @@ internal const val PARSER_OPTIONS = "This constructor is only here for binary co internal const val PARSER_OPTIONS_COPY = "This function is only here for binary compatibility. $MESSAGE_0_16" internal const val IS_COMPARABLE = - "This function is replaced by `isInterComparable()` to better reflect its purpose. $MESSAGE_0_16" -internal const val IS_COMPARABLE_REPLACE = "isInterComparable()" -internal const val IS_INTER_COMPARABLE_IMPORT = "org.jetbrains.kotlinx.dataframe.api.isInterComparable" + "This function is replaced by `valuesAreComparable()` to better reflect its purpose. $MESSAGE_0_16" +internal const val IS_COMPARABLE_REPLACE = "valuesAreComparable()" +internal const val IS_INTER_COMPARABLE_IMPORT = "org.jetbrains.kotlinx.dataframe.api.valuesAreComparable" // endregion diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/DataFrameTests.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/DataFrameTests.kt index 31671c5c90..b8e5d61c0c 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/DataFrameTests.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/DataFrameTests.kt @@ -83,7 +83,6 @@ import org.jetbrains.kotlinx.dataframe.api.intoRows import org.jetbrains.kotlinx.dataframe.api.isColumnGroup import org.jetbrains.kotlinx.dataframe.api.isEmpty import org.jetbrains.kotlinx.dataframe.api.isFrameColumn -import org.jetbrains.kotlinx.dataframe.api.isInterComparable import org.jetbrains.kotlinx.dataframe.api.isNA import org.jetbrains.kotlinx.dataframe.api.isNumber import org.jetbrains.kotlinx.dataframe.api.keysInto @@ -156,6 +155,7 @@ import org.jetbrains.kotlinx.dataframe.api.ungroup import org.jetbrains.kotlinx.dataframe.api.update import org.jetbrains.kotlinx.dataframe.api.value import org.jetbrains.kotlinx.dataframe.api.values +import org.jetbrains.kotlinx.dataframe.api.valuesAreComparable import org.jetbrains.kotlinx.dataframe.api.valuesNotNull import org.jetbrains.kotlinx.dataframe.api.where import org.jetbrains.kotlinx.dataframe.api.with @@ -2445,12 +2445,12 @@ class DataFrameTests : BaseTest() { ComparableTest(2, 2, "b", "b", "2", "2"), ).toDataFrame() - df.int.isInterComparable() shouldBe true - df.comparableInt.isInterComparable() shouldBe true - df.string.isInterComparable() shouldBe true - df.comparableString.isInterComparable() shouldBe true - df.comparableStar.isInterComparable() shouldBe false - df.comparableNothing.isInterComparable() shouldBe false + df.int.valuesAreComparable() shouldBe true + df.comparableInt.valuesAreComparable() shouldBe true + df.string.valuesAreComparable() shouldBe true + df.comparableString.valuesAreComparable() shouldBe true + df.comparableStar.valuesAreComparable() shouldBe false + df.comparableNothing.valuesAreComparable() shouldBe false } @Test