Skip to content
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

describe() fixes #937

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 11 additions & 3 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -2691,7 +2691,7 @@ public abstract interface class org/jetbrains/kotlinx/dataframe/api/ColumnDescri
public abstract fun getPath ()Lorg/jetbrains/kotlinx/dataframe/columns/ColumnPath;
public abstract fun getStd ()D
public abstract fun getTop ()Ljava/lang/Object;
public abstract fun getType ()Lkotlin/reflect/KType;
public abstract fun getType ()Ljava/lang/String;
public abstract fun getUnique ()I
}

Expand Down Expand Up @@ -2719,7 +2719,7 @@ public final class org/jetbrains/kotlinx/dataframe/api/ColumnDescription_Extensi
public static final fun ColumnDescription_top (Lorg/jetbrains/kotlinx/dataframe/ColumnsContainer;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
public static final fun ColumnDescription_top (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/Object;
public static final fun ColumnDescription_type (Lorg/jetbrains/kotlinx/dataframe/ColumnsContainer;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
public static final fun ColumnDescription_type (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Lkotlin/reflect/KType;
public static final fun ColumnDescription_type (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/String;
public static final fun ColumnDescription_unique (Lorg/jetbrains/kotlinx/dataframe/ColumnsContainer;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
public static final fun ColumnDescription_unique (Lorg/jetbrains/kotlinx/dataframe/DataRow;)I
public static final fun NullableColumnDescription_count (Lorg/jetbrains/kotlinx/dataframe/ColumnsContainer;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
Expand All @@ -2745,7 +2745,7 @@ public final class org/jetbrains/kotlinx/dataframe/api/ColumnDescription_Extensi
public static final fun NullableColumnDescription_top (Lorg/jetbrains/kotlinx/dataframe/ColumnsContainer;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
public static final fun NullableColumnDescription_top (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/Object;
public static final fun NullableColumnDescription_type (Lorg/jetbrains/kotlinx/dataframe/ColumnsContainer;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
public static final fun NullableColumnDescription_type (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Lkotlin/reflect/KType;
public static final fun NullableColumnDescription_type (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/String;
public static final fun NullableColumnDescription_unique (Lorg/jetbrains/kotlinx/dataframe/ColumnsContainer;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
public static final fun NullableColumnDescription_unique (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/Integer;
}
Expand Down Expand Up @@ -4146,9 +4146,11 @@ public final class org/jetbrains/kotlinx/dataframe/api/DataColumnArithmeticsKt {
}

public final class org/jetbrains/kotlinx/dataframe/api/DataColumnTypeKt {
public static final fun isBigNumber (Lorg/jetbrains/kotlinx/dataframe/DataColumn;)Z
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
Expand Down Expand Up @@ -10771,6 +10773,7 @@ public final class org/jetbrains/kotlinx/dataframe/math/BasicStats {

public final class org/jetbrains/kotlinx/dataframe/math/MeanKt {
public static final fun bigDecimalMean (Ljava/lang/Iterable;)D
public static final fun bigIntegerMean (Ljava/lang/Iterable;)D
public static final fun byteMean (Ljava/lang/Iterable;)D
public static final fun doubleMean (Ljava/lang/Iterable;Z)D
public static synthetic fun doubleMean$default (Ljava/lang/Iterable;ZILjava/lang/Object;)D
Expand All @@ -10794,6 +10797,8 @@ public final class org/jetbrains/kotlinx/dataframe/math/MedianKt {
public final class org/jetbrains/kotlinx/dataframe/math/StdKt {
public static final fun bigDecimalStd (Ljava/lang/Iterable;I)D
public static synthetic fun bigDecimalStd$default (Ljava/lang/Iterable;IILjava/lang/Object;)D
public static final fun bigIntegerStd (Ljava/lang/Iterable;I)D
public static synthetic fun bigIntegerStd$default (Ljava/lang/Iterable;IILjava/lang/Object;)D
public static final fun doubleStd (Ljava/lang/Iterable;ZI)D
public static synthetic fun doubleStd$default (Ljava/lang/Iterable;ZIILjava/lang/Object;)D
public static final fun floatStd (Ljava/lang/Iterable;ZI)D
Expand All @@ -10808,6 +10813,7 @@ public final class org/jetbrains/kotlinx/dataframe/math/StdKt {

public final class org/jetbrains/kotlinx/dataframe/math/StdMeanKt {
public static final fun bigDecimalVarianceAndMean (Ljava/lang/Iterable;)Lorg/jetbrains/kotlinx/dataframe/math/BasicStats;
public static final fun bigIntegerVarianceAndMean (Ljava/lang/Iterable;)Lorg/jetbrains/kotlinx/dataframe/math/BasicStats;
public static final fun doubleVarianceAndMean (Ljava/lang/Iterable;Z)Lorg/jetbrains/kotlinx/dataframe/math/BasicStats;
public static synthetic fun doubleVarianceAndMean$default (Ljava/lang/Iterable;ZILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/math/BasicStats;
public static final fun floatVarianceAndMean (Ljava/lang/Iterable;Z)Lorg/jetbrains/kotlinx/dataframe/math/BasicStats;
Expand All @@ -10818,8 +10824,10 @@ public final class org/jetbrains/kotlinx/dataframe/math/StdMeanKt {

public final class org/jetbrains/kotlinx/dataframe/math/SumKt {
public static final fun sum (Ljava/lang/Iterable;)Ljava/math/BigDecimal;
public static final fun sum (Ljava/lang/Iterable;)Ljava/math/BigInteger;
public static final fun sum (Ljava/lang/Iterable;Lkotlin/reflect/KType;)Ljava/lang/Number;
public static final fun sum (Lkotlin/sequences/Sequence;)Ljava/math/BigDecimal;
public static final fun sum (Lkotlin/sequences/Sequence;)Ljava/math/BigInteger;
public static final fun sumNullableT (Ljava/lang/Iterable;Lkotlin/reflect/KType;)Ljava/lang/Number;
public static final fun sumOf (Ljava/lang/Iterable;Lkotlin/reflect/KType;Lkotlin/jvm/functions/Function1;)Ljava/lang/Number;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import org.jetbrains.kotlinx.dataframe.impl.isNothing
import org.jetbrains.kotlinx.dataframe.impl.projectTo
import org.jetbrains.kotlinx.dataframe.type
import org.jetbrains.kotlinx.dataframe.typeClass
import org.jetbrains.kotlinx.dataframe.util.IS_COMPARABLE
import org.jetbrains.kotlinx.dataframe.util.IS_COMPARABLE_REPLACE
import org.jetbrains.kotlinx.dataframe.util.IS_INTER_COMPARABLE_IMPORT
import java.math.BigDecimal
import java.math.BigInteger
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
import kotlin.reflect.KClass
Expand Down Expand Up @@ -44,13 +49,26 @@ public inline fun <reified T> AnyCol.isType(): Boolean = type() == typeOf<T>()

public fun AnyCol.isNumber(): Boolean = isSubtypeOf<Number?>()

public fun AnyCol.isBigNumber(): Boolean = isSubtypeOf<BigInteger?>() || isSubtypeOf<BigDecimal?>()

public fun AnyCol.isList(): Boolean = typeClass == List::class

/** @include [isInterComparable] */
@Deprecated(
message = IS_COMPARABLE,
replaceWith = ReplaceWith(IS_COMPARABLE_REPLACE, IS_INTER_COMPARABLE_IMPORT),
level = DeprecationLevel.WARNING,
)
public fun AnyCol.isComparable(): Boolean = isInterComparable()

/**
* Returns `true` if [this] column is comparable, i.e. its type is a subtype of [Comparable] and its
* type argument is not [Nothing].
* Returns `true` if [this] column is inter-comparable, i.e.
* its elements can be compared with each other.
*
* Technically, this means the elements' common type is a subtype of [Comparable] with
* the type argument not being [Nothing].
*/
public fun AnyCol.isComparable(): Boolean =
public fun AnyCol.isInterComparable(): 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 @@ -5,10 +5,13 @@ import org.jetbrains.kotlinx.dataframe.ColumnsSelector
import org.jetbrains.kotlinx.dataframe.DataColumn
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
import org.jetbrains.kotlinx.dataframe.impl.nothingType
import org.jetbrains.kotlinx.dataframe.impl.nullableNothingType
import org.jetbrains.kotlinx.dataframe.math.cumSum
import org.jetbrains.kotlinx.dataframe.math.defaultCumSumSkipNA
import org.jetbrains.kotlinx.dataframe.typeClass
import java.math.BigDecimal
import java.math.BigInteger
import kotlin.reflect.KProperty
import kotlin.reflect.typeOf

Expand All @@ -17,20 +20,59 @@ import kotlin.reflect.typeOf
public fun <T : Number?> DataColumn<T>.cumSum(skipNA: Boolean = defaultCumSumSkipNA): DataColumn<T> =
when (type()) {
typeOf<Double>() -> cast<Double>().cumSum(skipNA).cast()

typeOf<Double?>() -> cast<Double?>().cumSum(skipNA).cast()

typeOf<Float>() -> cast<Float>().cumSum(skipNA).cast()

typeOf<Float?>() -> cast<Float?>().cumSum(skipNA).cast()

typeOf<Int>() -> cast<Int>().cumSum().cast()

// TODO cumSum for Byte returns Int but is converted back to T: Byte, Issue #558
typeOf<Byte>() -> cast<Byte>().cumSum().map { it.toByte() }.cast()

// TODO cumSum for Short returns Int but is converted back to T: Short, Issue #558
typeOf<Short>() -> cast<Short>().cumSum().map { it.toShort() }.cast()

typeOf<Int?>() -> cast<Int?>().cumSum(skipNA).cast()

// TODO cumSum for Byte? returns Int? but is converted back to T: Byte?, Issue #558
typeOf<Byte?>() -> cast<Byte?>().cumSum(skipNA).map { it?.toByte() }.cast()

// TODO cumSum for Short? returns Int? but is converted back to T: Short?, Issue #558
typeOf<Short?>() -> cast<Short?>().cumSum(skipNA).map { it?.toShort() }.cast()

typeOf<Long>() -> cast<Long>().cumSum().cast()

typeOf<Long?>() -> cast<Long?>().cumSum(skipNA).cast()

typeOf<BigInteger>() -> cast<BigInteger>().cumSum().cast()

typeOf<BigInteger?>() -> cast<BigInteger?>().cumSum(skipNA).cast()

typeOf<BigDecimal>() -> cast<BigDecimal>().cumSum().cast()

typeOf<BigDecimal?>() -> cast<BigDecimal?>().cumSum(skipNA).cast()

typeOf<Number?>(), typeOf<Number>() -> convertToDouble().cumSum(skipNA).cast()

// Cumsum for empty column or column with just null is itself
nothingType, nullableNothingType -> this

else -> error("Cumsum for type ${type()} is not supported")
}

private val supportedClasses = setOf(Double::class, Float::class, Int::class, Long::class, BigDecimal::class)
private val supportedClasses = setOf(
Double::class,
Float::class,
Int::class,
Byte::class,
Short::class,
Long::class,
BigInteger::class,
BigDecimal::class,
)

// endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
import org.jetbrains.kotlinx.dataframe.impl.api.describeImpl
import kotlin.reflect.KProperty
import kotlin.reflect.KType

// region DataSchema
@DataSchema
public interface ColumnDescription {
public val name: String
public val path: ColumnPath
public val type: KType
public val type: String
public val count: Int
public val unique: Int
public val nulls: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
import org.jetbrains.kotlinx.dataframe.columns.values
import org.jetbrains.kotlinx.dataframe.impl.aggregation.aggregators.Aggregators
import org.jetbrains.kotlinx.dataframe.impl.aggregation.comparableColumns
import org.jetbrains.kotlinx.dataframe.impl.aggregation.interComparableColumns
import org.jetbrains.kotlinx.dataframe.impl.aggregation.modes.aggregateAll
import org.jetbrains.kotlinx.dataframe.impl.aggregation.modes.aggregateFor
import org.jetbrains.kotlinx.dataframe.impl.aggregation.modes.aggregateOfDelegated
Expand Down Expand Up @@ -52,7 +52,7 @@ public inline fun <reified T : Comparable<T>> AnyRow.rowMaxOf(): T = rowMaxOfOrN

// region DataFrame

public fun <T> DataFrame<T>.max(): DataRow<T> = maxFor(comparableColumns())
public fun <T> DataFrame<T>.max(): DataRow<T> = maxFor(interComparableColumns())

public fun <T, C : Comparable<C>> DataFrame<T>.maxFor(columns: ColumnsForAggregateSelector<T, C?>): DataRow<T> =
Aggregators.max.aggregateFor(this, columns)
Expand Down Expand Up @@ -121,7 +121,7 @@ public fun <T, C : Comparable<C>> DataFrame<T>.maxByOrNull(column: KProperty<C?>

// region GroupBy

public fun <T> Grouped<T>.max(): DataFrame<T> = maxFor(comparableColumns())
public fun <T> Grouped<T>.max(): DataFrame<T> = maxFor(interComparableColumns())

public fun <T, C : Comparable<C>> Grouped<T>.maxFor(columns: ColumnsForAggregateSelector<T, C?>): DataFrame<T> =
Aggregators.max.aggregateFor(this, columns)
Expand Down Expand Up @@ -218,7 +218,7 @@ public fun <T, C : Comparable<C>> Pivot<T>.maxBy(column: KProperty<C?>): Reduced

// region PivotGroupBy

public fun <T> PivotGroupBy<T>.max(separate: Boolean = false): DataFrame<T> = maxFor(separate, comparableColumns())
public fun <T> PivotGroupBy<T>.max(separate: Boolean = false): DataFrame<T> = maxFor(separate, interComparableColumns())

public fun <T, R : Comparable<R>> PivotGroupBy<T>.maxFor(
separate: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
import org.jetbrains.kotlinx.dataframe.impl.aggregation.aggregators.Aggregators
import org.jetbrains.kotlinx.dataframe.impl.aggregation.aggregators.cast
import org.jetbrains.kotlinx.dataframe.impl.aggregation.comparableColumns
import org.jetbrains.kotlinx.dataframe.impl.aggregation.interComparableColumns
import org.jetbrains.kotlinx.dataframe.impl.aggregation.modes.aggregateAll
import org.jetbrains.kotlinx.dataframe.impl.aggregation.modes.aggregateFor
import org.jetbrains.kotlinx.dataframe.impl.aggregation.modes.aggregateOf
Expand Down Expand Up @@ -53,7 +53,7 @@ public inline fun <reified T : Comparable<T>> AnyRow.rowMedianOf(): T =

// region DataFrame

public fun <T> DataFrame<T>.median(): DataRow<T> = medianFor(comparableColumns())
public fun <T> DataFrame<T>.median(): DataRow<T> = medianFor(interComparableColumns())

public fun <T, C : Comparable<C>> DataFrame<T>.medianFor(columns: ColumnsForAggregateSelector<T, C?>): DataRow<T> =
Aggregators.median.aggregateFor(this, columns)
Expand Down Expand Up @@ -96,7 +96,7 @@ public inline fun <T, reified R : Comparable<R>> DataFrame<T>.medianOf(

// region GroupBy

public fun <T> Grouped<T>.median(): DataFrame<T> = medianFor(comparableColumns())
public fun <T> Grouped<T>.median(): DataFrame<T> = medianFor(interComparableColumns())

public fun <T, C : Comparable<C>> Grouped<T>.medianFor(columns: ColumnsForAggregateSelector<T, C?>): DataFrame<T> =
Aggregators.median.aggregateFor(this, columns)
Expand Down Expand Up @@ -134,7 +134,7 @@ public inline fun <T, reified R : Comparable<R>> Grouped<T>.medianOf(

// region Pivot

public fun <T> Pivot<T>.median(separate: Boolean = false): DataRow<T> = medianFor(separate, comparableColumns())
public fun <T> Pivot<T>.median(separate: Boolean = false): DataRow<T> = medianFor(separate, interComparableColumns())

public fun <T, C : Comparable<C>> Pivot<T>.medianFor(
separate: Boolean = false,
Expand Down Expand Up @@ -174,7 +174,7 @@ public inline fun <T, reified R : Comparable<R>> Pivot<T>.medianOf(
// region PivotGroupBy

public fun <T> PivotGroupBy<T>.median(separate: Boolean = false): DataFrame<T> =
medianFor(separate, comparableColumns())
medianFor(separate, interComparableColumns())

public fun <T, C : Comparable<C>> PivotGroupBy<T>.medianFor(
separate: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
import org.jetbrains.kotlinx.dataframe.columns.values
import org.jetbrains.kotlinx.dataframe.impl.aggregation.aggregators.Aggregators
import org.jetbrains.kotlinx.dataframe.impl.aggregation.comparableColumns
import org.jetbrains.kotlinx.dataframe.impl.aggregation.interComparableColumns
import org.jetbrains.kotlinx.dataframe.impl.aggregation.modes.aggregateAll
import org.jetbrains.kotlinx.dataframe.impl.aggregation.modes.aggregateFor
import org.jetbrains.kotlinx.dataframe.impl.aggregation.modes.aggregateOfDelegated
Expand Down Expand Up @@ -52,7 +52,7 @@ public inline fun <reified T : Comparable<T>> AnyRow.rowMinOf(): T = rowMinOfOrN

// region DataFrame

public fun <T> DataFrame<T>.min(): DataRow<T> = minFor(comparableColumns())
public fun <T> DataFrame<T>.min(): DataRow<T> = minFor(interComparableColumns())

public fun <T, C : Comparable<C>> DataFrame<T>.minFor(columns: ColumnsForAggregateSelector<T, C?>): DataRow<T> =
Aggregators.min.aggregateFor(this, columns)
Expand Down Expand Up @@ -121,7 +121,7 @@ public fun <T, C : Comparable<C>> DataFrame<T>.minByOrNull(column: KProperty<C?>

// region GroupBy

public fun <T> Grouped<T>.min(): DataFrame<T> = minFor(comparableColumns())
public fun <T> Grouped<T>.min(): DataFrame<T> = minFor(interComparableColumns())

public fun <T, C : Comparable<C>> Grouped<T>.minFor(columns: ColumnsForAggregateSelector<T, C?>): DataFrame<T> =
Aggregators.min.aggregateFor(this, columns)
Expand Down Expand Up @@ -219,7 +219,7 @@ public fun <T, C : Comparable<C>> Pivot<T>.minBy(column: KProperty<C?>): Reduced

// region PivotGroupBy

public fun <T> PivotGroupBy<T>.min(separate: Boolean = false): DataFrame<T> = minFor(separate, comparableColumns())
public fun <T> PivotGroupBy<T>.min(separate: Boolean = false): DataFrame<T> = minFor(separate, interComparableColumns())

public fun <T, R : Comparable<R>> PivotGroupBy<T>.minFor(
separate: Boolean = false,
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(isComparable())
require(isInterComparable())
return this as DataColumn<Comparable<T>>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import org.jetbrains.kotlinx.dataframe.DataRow
import org.jetbrains.kotlinx.dataframe.api.Infer
import org.jetbrains.kotlinx.dataframe.impl.columns.createColumnGuessingType
import org.jetbrains.kotlinx.dataframe.util.GUESS_VALUE_TYPE
import java.math.BigDecimal
import java.math.BigInteger
import kotlin.reflect.KClass
import kotlin.reflect.KType
import kotlin.reflect.KTypeParameter
Expand All @@ -29,6 +31,7 @@ import kotlin.reflect.full.superclasses
import kotlin.reflect.full.withNullability
import kotlin.reflect.jvm.jvmErasure
import kotlin.reflect.typeOf
import kotlin.toBigDecimal as toBigDecimalKotlin

internal inline fun <reified T> KClass<*>.createTypeUsing() = typeOf<T>().projectTo(this)

Expand Down Expand Up @@ -546,12 +549,10 @@ internal fun guessValueType(
internal val KType.isNothing: Boolean
get() = classifier == Nothing::class

internal fun nothingType(nullable: Boolean): KType =
if (nullable) {
typeOf<List<Nothing?>>()
} else {
typeOf<List<Nothing>>()
}.arguments.first().type!!
internal val nothingType: KType = typeOf<List<Nothing>>().arguments.first().type!!
internal val nullableNothingType: KType = typeOf<List<Nothing?>>().arguments.first().type!!

internal fun nothingType(nullable: Boolean): KType = if (nullable) nullableNothingType else nothingType

@OptIn(ExperimentalUnsignedTypes::class)
private val primitiveArrayClasses = setOf(
Expand Down Expand Up @@ -646,3 +647,18 @@ internal fun Any.asArrayAsListOrNull(): List<*>? =
is Array<*> -> asList()
else -> null
}

internal fun Any.isBigNumber(): Boolean = this is BigInteger || this is BigDecimal

internal fun Number.toBigDecimal(): BigDecimal =
when (this) {
is BigDecimal -> this
is BigInteger -> this.toBigDecimalKotlin()
is Int -> this.toBigDecimalKotlin()
is Byte -> this.toInt().toBigDecimalKotlin()
is Short -> this.toInt().toBigDecimalKotlin()
is Long -> this.toBigDecimalKotlin()
is Float -> this.toBigDecimalKotlin()
is Double -> this.toBigDecimalKotlin()
else -> BigDecimal(this.toString())
}
Loading
Loading