Skip to content

Commit

Permalink
renamed isInterComparable to valuesAreComparable based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolanrensen committed Nov 21, 2024
1 parent 8889e13 commit 96ed593
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,22 @@ public fun AnyCol.isBigNumber(): Boolean = isSubtypeOf<BigInteger?>() || 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<Comparable<*>?>() &&
type().projectTo(Comparable::class).arguments[0].let {
it != KTypeProjection.STAR &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public fun DataColumn<Any>.asNumbers(): ValueColumn<Number> {
}

public fun <T> DataColumn<T>.asComparable(): DataColumn<Comparable<T>> {
require(isInterComparable())
require(valuesAreComparable())
return this as DataColumn<Comparable<T>>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -15,7 +15,7 @@ internal inline fun <T> Aggregatable<T>.remainingColumns(
): ColumnsSelector<T, Any?> = remainingColumnsSelector().filter { predicate(it.data) }

internal fun <T> Aggregatable<T>.interComparableColumns() =
remainingColumns { it.isInterComparable() } as ColumnsSelector<T, Comparable<Any?>>
remainingColumns { it.valuesAreComparable() } as ColumnsSelector<T, Comparable<Any?>>

internal fun <T> Aggregatable<T>.numberColumns() = remainingColumns { it.isNumber() } as ColumnsSelector<T, Number?>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -39,7 +39,7 @@ internal fun describeImpl(cols: List<AnyCol>): DataFrame<ColumnDescription> {
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() }
Expand All @@ -59,15 +59,15 @@ internal fun describeImpl(cols: List<AnyCol>): DataFrame<ColumnDescription> {
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()
}
}
}
Expand Down Expand Up @@ -105,9 +105,9 @@ private fun List<AnyCol>.collectAll(atAnyDepth: Boolean): List<AnyCol> =
}

/** Converts a column to a comparable column if it is not already comparable. */
private fun DataColumn<Any?>.convertToInterComparableOrNull(): DataColumn<Comparable<Any?>>? =
private fun DataColumn<Any?>.convertToComparableOrNull(): DataColumn<Comparable<Any?>>? =
when {
isInterComparable() -> asComparable()
valuesAreComparable() -> asComparable()

// Found incomparable number types, convert all to Double or BigDecimal first
isNumber() ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -107,7 +107,7 @@ public object KotlinNotebookPluginUtils {
private fun createComparator(sortKeys: List<ColumnPath>, isDesc: List<Boolean>): Comparator<DataRow<*>> {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 96ed593

Please sign in to comment.