File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
main/kotlin/org/jetbrains/kotlinx/dataframe/io
test/kotlin/org/jetbrains/kotlinx/dataframe/io Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -274,7 +274,12 @@ public fun DataFrame.Companion.readDelim(
274
274
val colType = colTypes[colName] ? : defaultColType
275
275
var hasNulls = false
276
276
val values = records.map {
277
- it[colIndex].ifEmpty {
277
+ if (it.isSet(colIndex)) {
278
+ it[colIndex].ifEmpty {
279
+ hasNulls = true
280
+ null
281
+ }
282
+ } else {
278
283
hasNulls = true
279
284
null
280
285
}
Original file line number Diff line number Diff line change 1
1
package org.jetbrains.kotlinx.dataframe.io
2
2
3
+ import io.kotest.assertions.throwables.shouldNotThrowAny
3
4
import io.kotest.matchers.nulls.shouldNotBeNull
4
5
import io.kotest.matchers.shouldBe
5
6
import kotlinx.datetime.LocalDateTime
@@ -137,6 +138,23 @@ class CsvTests {
137
138
df[" floatDuration" ].type() shouldBe typeOf<String >()
138
139
}
139
140
141
+ @Test
142
+ fun `if record has fewer columns than header then pad it with nulls` () {
143
+ val csvContent = """ col1,col2,col3
144
+ 568,801,587
145
+ 780,588
146
+ """ .trimIndent()
147
+
148
+ val df = shouldNotThrowAny {
149
+ DataFrame .readDelimStr(csvContent)
150
+ }
151
+
152
+ df shouldBe dataFrameOf(" col1" , " col2" , " col3" )(
153
+ 568 , 801 , 587 ,
154
+ 780 , 588 , null
155
+ )
156
+ }
157
+
140
158
@Test
141
159
fun `write and read frame column` () {
142
160
val df = dataFrameOf(" a" , " b" , " c" )(
You can’t perform that action at this time.
0 commit comments