Skip to content

Commit 8180926

Browse files
committed
assertEstimations for signed and unsigned integer types
1 parent fa5b956 commit 8180926

File tree

2 files changed

+66
-13
lines changed

2 files changed

+66
-13
lines changed

dataframe-arrow/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/arrow.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ public fun DataFrame.Companion.readArrowFeather(channel: SeekableByteChannel, al
139139

140140
private fun BitVector.values(range: IntRange): List<Boolean?> = range.map { getObject(it) }
141141

142-
private fun UInt1Vector.values(range: IntRange): List<Byte?> = range.map { getObject(it) }
143-
private fun UInt2Vector.values(range: IntRange): List<Char?> = range.map { getObject(it) }
142+
private fun UInt1Vector.values(range: IntRange): List<Short?> = range.map { getObjectNoOverflow(it) }
143+
private fun UInt2Vector.values(range: IntRange): List<Int?> = range.map { getObject(it).code }
144144
private fun UInt4Vector.values(range: IntRange): List<Long?> = range.map { getObjectNoOverflow(it) }
145145
private fun UInt8Vector.values(range: IntRange): List<BigInteger?> = range.map { getObjectNoOverflow(it) }
146146

dataframe-arrow/src/test/kotlin/exampleEstimatesAssertions.kt

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import org.jetbrains.kotlinx.dataframe.AnyFrame
33
import org.jetbrains.kotlinx.dataframe.DataColumn
44
import org.jetbrains.kotlinx.dataframe.api.forEach
55
import org.jetbrains.kotlinx.dataframe.api.forEachIndexed
6+
import java.math.BigInteger
7+
import kotlin.math.absoluteValue
68
import kotlin.reflect.typeOf
79

810
/**
@@ -22,20 +24,71 @@ internal fun assertEstimations(exampleFrame: AnyFrame) {
2224
element shouldBe "Test Example ${iBatch(i)}"
2325
}
2426

25-
val utf8StringCol = exampleFrame["utf8String"]
26-
val largeStringCol = exampleFrame["largeString"]
27+
val utf8StringCol = exampleFrame["utf8String"] as DataColumn<String?>
28+
utf8StringCol.type() shouldBe typeOf<String?>()
29+
utf8StringCol.forEachIndexed { i, element ->
30+
element shouldBe "Тестовый пример ${iBatch(i)}"
31+
}
32+
33+
val largeStringCol = exampleFrame["largeString"] as DataColumn<String?>
34+
largeStringCol.type() shouldBe typeOf<String?>()
35+
largeStringCol.forEachIndexed { i, element ->
36+
element shouldBe "Test Example Should Be Large ${iBatch(i)}"
37+
}
38+
39+
val booleanCol = exampleFrame["boolean"] as DataColumn<Boolean?>
40+
booleanCol.type() shouldBe typeOf<Boolean?>()
41+
booleanCol.forEachIndexed { i, element ->
42+
element shouldBe (iBatch(i) % 2 == 0)
43+
}
44+
45+
val byteCol = exampleFrame["byte"] as DataColumn<Byte?>
46+
byteCol.type() shouldBe typeOf<Byte?>()
47+
byteCol.forEachIndexed { i, element ->
48+
element shouldBe (iBatch(i) * 10).toByte()
49+
}
50+
51+
val shortCol = exampleFrame["short"] as DataColumn<Short?>
52+
shortCol.type() shouldBe typeOf<Short?>()
53+
shortCol.forEachIndexed { i, element ->
54+
element shouldBe (iBatch(i) * 1000).toShort()
55+
}
2756

28-
val booleanCol = exampleFrame["boolean"]
57+
val intCol = exampleFrame["int"] as DataColumn<Int?>
58+
intCol.type() shouldBe typeOf<Int?>()
59+
intCol.forEachIndexed { i, element ->
60+
element shouldBe (iBatch(i) * 100000000).toInt()
61+
}
2962

30-
val byteCol = exampleFrame["byte"]
31-
val shortCol = exampleFrame["short"]
32-
val intCol = exampleFrame["int"]
33-
val longIntCol = exampleFrame["longInt"]
63+
val longCol = exampleFrame["longInt"] as DataColumn<Long?>
64+
longCol.type() shouldBe typeOf<Long?>()
65+
longCol.forEachIndexed { i, element ->
66+
element shouldBe iBatch(i) * 100000000000000000L
67+
}
3468

35-
val unsignedByteCol = exampleFrame["unsigned_byte"]
36-
val unsignedShortCol = exampleFrame["unsigned_short"]
37-
val unsignedIntCol = exampleFrame["unsigned_int"]
38-
val unsignedLongIntCol = exampleFrame["unsigned_longInt"]
69+
val unsignedByteCol = exampleFrame["unsigned_byte"] as DataColumn<Short?>
70+
unsignedByteCol.type() shouldBe typeOf<Short?>()
71+
unsignedByteCol.forEachIndexed { i, element ->
72+
element shouldBe (iBatch(i) * 10 % (Byte.MIN_VALUE.toShort() * 2).absoluteValue).toShort()
73+
}
74+
75+
val unsignedShortCol = exampleFrame["unsigned_short"] as DataColumn<Int?>
76+
unsignedShortCol.type() shouldBe typeOf<Int?>()
77+
unsignedShortCol.forEachIndexed { i, element ->
78+
element shouldBe (iBatch(i) * 1000 % (Short.MIN_VALUE.toInt() * 2).absoluteValue)
79+
}
80+
81+
val unsignedIntCol = exampleFrame["unsigned_int"] as DataColumn<Long?>
82+
unsignedIntCol.type() shouldBe typeOf<Long?>()
83+
unsignedIntCol.forEachIndexed { i, element ->
84+
element shouldBe (iBatch(i).toLong() * 100000000 % (Int.MIN_VALUE.toLong() * 2).absoluteValue)
85+
}
86+
87+
val unsignedLongIntCol = exampleFrame["unsigned_longInt"] as DataColumn<BigInteger?>
88+
unsignedLongIntCol.type() shouldBe typeOf<BigInteger?>()
89+
unsignedLongIntCol.forEachIndexed { i, element ->
90+
element shouldBe (iBatch(i).toBigInteger() * 100000000000000000L.toBigInteger() % (Long.MIN_VALUE.toBigInteger() * 2.toBigInteger()).abs())
91+
}
3992

4093
val dateCol = exampleFrame["date32"]
4194
val datetimeCol = exampleFrame["date64"]

0 commit comments

Comments
 (0)