Skip to content

Commit 49c1cbb

Browse files
committed
assertEstimations for LocalTime
1 parent d158e16 commit 49c1cbb

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import java.nio.file.Files
5757
import java.time.Duration
5858
import java.time.LocalDate
5959
import java.time.LocalDateTime
60+
import java.time.LocalTime
6061
import kotlin.reflect.typeOf
6162

6263
public class ArrowFeather : SupportedFormat {
@@ -161,10 +162,11 @@ private fun DateDayVector.values(range: IntRange): List<LocalDate?> = range.map
161162
}
162163
private fun DateMilliVector.values(range: IntRange): List<LocalDateTime?> = range.map { getObject(it) }
163164

164-
private fun TimeNanoVector.values(range: IntRange): List<Long?> = range.map { getObject(it) }
165-
private fun TimeMicroVector.values(range: IntRange): List<Long?> = range.map { getObject(it) }
166-
private fun TimeMilliVector.values(range: IntRange): List<LocalDateTime?> = range.map { getObject(it) }
167-
private fun TimeSecVector.values(range: IntRange): List<Int?> = range.map { getObject(it) }
165+
private fun TimeNanoVector.values(range: IntRange): List<LocalTime?> = range.map { LocalTime.ofNanoOfDay(get(it)) }
166+
private fun TimeMicroVector.values(range: IntRange): List<LocalTime?> = range.map { LocalTime.ofNanoOfDay(get(it) * 1000) }
167+
private fun TimeMilliVector.values(range: IntRange): List<LocalTime?> = range.map { LocalTime.ofNanoOfDay(get(it).toLong() * 1000_000) }
168+
private fun TimeSecVector.values(range: IntRange): List<LocalTime?> = range.map { LocalTime.ofSecondOfDay(get(it).toLong()) }
169+
168170
private fun StructVector.values(range: IntRange): List<Map<String, Any?>?> = range.map { getObject(it) }
169171

170172
private fun VarCharVector.values(range: IntRange): List<String?> = range.map {

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import io.kotest.matchers.shouldBe
22
import org.jetbrains.kotlinx.dataframe.AnyFrame
33
import org.jetbrains.kotlinx.dataframe.DataColumn
4-
import org.jetbrains.kotlinx.dataframe.api.forEach
54
import org.jetbrains.kotlinx.dataframe.api.forEachIndexed
65
import java.math.BigInteger
76
import java.time.LocalDate
87
import java.time.LocalDateTime
8+
import java.time.LocalTime
99
import java.time.ZoneOffset
1010
import kotlin.math.absoluteValue
1111
import kotlin.math.pow
@@ -118,9 +118,28 @@ internal fun assertEstimations(exampleFrame: AnyFrame) {
118118
element shouldBe LocalDateTime.ofEpochSecond(iBatch(i).toLong() * 60 * 60 * 24 * 30, 0, ZoneOffset.UTC)
119119
}
120120

121-
val timeSecCol = exampleFrame["time32_seconds"]
122-
val timeMilliCol = exampleFrame["time32_milli"]
121+
val timeSecCol = exampleFrame["time32_seconds"] as DataColumn<LocalTime?>
122+
timeSecCol.type() shouldBe typeOf<LocalTime?>()
123+
timeSecCol.forEachIndexed { i, element ->
124+
element shouldBe LocalTime.ofSecondOfDay(iBatch(i).toLong())
125+
}
126+
127+
val timeMilliCol = exampleFrame["time32_milli"] as DataColumn<LocalTime?>
128+
timeMilliCol.type() shouldBe typeOf<LocalTime?>()
129+
timeMilliCol.forEachIndexed { i, element ->
130+
element shouldBe LocalTime.ofNanoOfDay(iBatch(i).toLong() * 1000_000)
131+
}
132+
133+
val timeMicroCol = exampleFrame["time64_micro"] as DataColumn<LocalTime?>
134+
timeMicroCol.type() shouldBe typeOf<LocalTime?>()
135+
timeMicroCol.forEachIndexed { i, element ->
136+
element shouldBe LocalTime.ofNanoOfDay(iBatch(i).toLong() * 1000)
137+
}
138+
139+
val timeNanoCol = exampleFrame["time64_nano"] as DataColumn<LocalTime?>
140+
timeNanoCol.type() shouldBe typeOf<LocalTime?>()
141+
timeNanoCol.forEachIndexed { i, element ->
142+
element shouldBe LocalTime.ofNanoOfDay(iBatch(i).toLong())
143+
}
123144

124-
val timeMicroCol = exampleFrame["time64_micro"]
125-
val timeNanoCol = exampleFrame["time64_nano"]
126145
}

0 commit comments

Comments
 (0)