Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ internal fun renderType(type: KType?): String {
else -> {
val fullName = type.jvmErasure.qualifiedName ?: return type.toString()
val name = when {
// catching cases like `typeOf<Array<Int>>().jvmErasure.qualifiedName == "IntArray"`
// https://github.com/Kotlin/dataframe/issues/678
type.isSubtypeOf(typeOf<Array<*>>()) ->
"Array"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,14 +607,7 @@ internal val KClass<*>.isArray: Boolean
* Use [KType.isArray] to also check for `Array<>`.
*/
internal val KType.isPrimitiveArray: Boolean
get() =
if (arguments.isNotEmpty()) {
// Catching https://github.com/Kotlin/dataframe/issues/678
// as typeOf<Array<Int>>().classifier == IntArray::class
false
} else {
(classifier as? KClass<*>)?.isPrimitiveArray == true
}
get() = (classifier as? KClass<*>)?.isPrimitiveArray == true

/**
* Returns `true` if this type is of an array, either a primitive array like `XArray` or `Array<>`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,33 @@ import kotlin.reflect.typeOf

class ConstructorsTests {

@Test
fun `columnOf correct types`() {
val intCol = columnOf(1, 2, 3)
intCol.type shouldBe typeOf<Int>()

val stringCol = columnOf("a", "b", "c")
stringCol.type shouldBe typeOf<String>()

val nullableIntCol = columnOf(1, 2, null)
nullableIntCol.type shouldBe typeOf<Int?>()

val doubleCol = columnOf(1.0, 2.5, 3.7)
doubleCol.type shouldBe typeOf<Double>()

val booleanCol = columnOf(true, false, true)
booleanCol.type shouldBe typeOf<Boolean>()

val arrayIntCol = columnOf(arrayOf(1))
arrayIntCol.type shouldBe typeOf<Array<Int>>()

val intArrayCol = columnOf(intArrayOf(1))
intArrayCol.type shouldBe typeOf<IntArray>()

val nullableArrayIntCol = columnOf(arrayOf(1, null))
nullableArrayIntCol.type shouldBe typeOf<Array<Int?>>()
}

@Test
fun `untitled column naming`() {
val builder = DynamicDataFrameBuilder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.jetbrains.kotlinx.dataframe.impl

import io.kotest.matchers.shouldBe
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.LocalTime
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.junit.Test
import java.net.URL
import kotlin.reflect.typeOf
import kotlin.time.Duration
import kotlin.time.Instant

class Rendering {

@Test
fun `renderType by KType test`() {
// null
renderType(null) shouldBe "*"

// Nothing?
renderType(typeOf<Nothing?>()) shouldBe "Nothing?"

// Primitive arrays
renderType(typeOf<IntArray>()) shouldBe "IntArray"
renderType(typeOf<ByteArray>()) shouldBe "ByteArray"
renderType(typeOf<LongArray>()) shouldBe "LongArray"
renderType(typeOf<DoubleArray>()) shouldBe "DoubleArray"
renderType(typeOf<FloatArray>()) shouldBe "FloatArray"
renderType(typeOf<BooleanArray>()) shouldBe "BooleanArray"

// Array<T>
renderType(typeOf<Array<Int>>()) shouldBe "Array<Int>"
renderType(typeOf<Array<String>>()) shouldBe "Array<String>"
renderType(typeOf<Array<Int?>>()) shouldBe "Array<Int?>"
renderType(typeOf<Array<*>>()) shouldBe "Array<*>"

// URL
renderType(typeOf<URL>()) shouldBe "URL"

// kotlinx.datetime
renderType(typeOf<LocalDateTime>()) shouldBe "LocalDateTime"
renderType(typeOf<LocalTime>()) shouldBe "LocalTime"

// kotlin.collections
renderType(typeOf<List<Int>>()) shouldBe "List<Int>"
renderType(typeOf<Map<String, Int>>()) shouldBe "Map<String, Int>"
renderType(typeOf<Set<String>>()) shouldBe "Set<String>"
renderType(typeOf<MutableList<Int>>()) shouldBe "List<Int>"

// kotlin.time
renderType(typeOf<Duration>()) shouldBe "Duration"
renderType(typeOf<Instant>()) shouldBe "Instant"

// kotlin.*
renderType(typeOf<Int>()) shouldBe "Int"
renderType(typeOf<String>()) shouldBe "String"
renderType(typeOf<Boolean>()) shouldBe "Boolean"
renderType(typeOf<Double>()) shouldBe "Double"

// nullable types
renderType(typeOf<Int?>()) shouldBe "Int?"
renderType(typeOf<String?>()) shouldBe "String?"
renderType(typeOf<List<Int>?>()) shouldBe "List<Int>?"
renderType(typeOf<List<Int?>>()) shouldBe "List<Int?>"

// dataframe types
renderType(typeOf<DataFrame<*>>()) shouldBe "DataFrame<*>"

// non-kotlin types (fully qualified)
renderType(typeOf<java.math.BigDecimal>()) shouldBe "java.math.BigDecimal"

// variance
renderType(typeOf<List<*>>()) shouldBe "List<*>"
renderType(typeOf<Comparable<in Int>>()) shouldBe "Comparable<in Int>"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.jetbrains.kotlinx.dataframe.impl

import io.kotest.matchers.shouldBe
import org.junit.Test
import kotlin.reflect.typeOf

class TypeUtils {
@Test
fun `isPrimitiveArray test`() {
// All primitive array types -> true
typeOf<IntArray>().isPrimitiveArray shouldBe true
typeOf<ByteArray>().isPrimitiveArray shouldBe true
typeOf<ShortArray>().isPrimitiveArray shouldBe true
typeOf<LongArray>().isPrimitiveArray shouldBe true
typeOf<FloatArray>().isPrimitiveArray shouldBe true
typeOf<DoubleArray>().isPrimitiveArray shouldBe true
typeOf<BooleanArray>().isPrimitiveArray shouldBe true
typeOf<CharArray>().isPrimitiveArray shouldBe true

// Unsigned primitive arrays -> true
@OptIn(ExperimentalUnsignedTypes::class)
run {
typeOf<UByteArray>().isPrimitiveArray shouldBe true
typeOf<UShortArray>().isPrimitiveArray shouldBe true
typeOf<UIntArray>().isPrimitiveArray shouldBe true
typeOf<ULongArray>().isPrimitiveArray shouldBe true
}

// Nullable primitive arrays -> true
typeOf<IntArray?>().isPrimitiveArray shouldBe true
typeOf<ByteArray?>().isPrimitiveArray shouldBe true
typeOf<DoubleArray?>().isPrimitiveArray shouldBe true
typeOf<BooleanArray?>().isPrimitiveArray shouldBe true

// Array<T> (has type arguments) -> false
typeOf<Array<Int>>().isPrimitiveArray shouldBe false
typeOf<Array<Int?>>().isPrimitiveArray shouldBe false
typeOf<Array<String>>().isPrimitiveArray shouldBe false
typeOf<Array<*>>().isPrimitiveArray shouldBe false
typeOf<Array<Any>>().isPrimitiveArray shouldBe false

// Non-array types -> false
typeOf<Int>().isPrimitiveArray shouldBe false
typeOf<String>().isPrimitiveArray shouldBe false
typeOf<List<Int>>().isPrimitiveArray shouldBe false
typeOf<Map<String, Int>>().isPrimitiveArray shouldBe false
typeOf<Any>().isPrimitiveArray shouldBe false
typeOf<Nothing?>().isPrimitiveArray shouldBe false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@ class RenderingTests : TestBase() {
val df = dataFrameOf(
columnOf(1, null).named("a"),
columnOf(intArrayOf(1), intArrayOf(2)).named("b"),
// TODO https://github.com/Kotlin/dataframe/issues/679
// columnOf(arrayOf(1), arrayOf(2)).named("d"),
DataColumn.createValueColumn("c", listOf(arrayOf(1), arrayOf(2))),
columnOf(arrayOf(1), arrayOf(2)).named("c"),
columnOf(arrayOf(1, null), arrayOf(2, null)).named("d"),
)

Expand Down
Loading