@@ -13,6 +13,7 @@ import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
13
13
import org.jetbrains.kotlinx.dataframe.api.group
14
14
import org.jetbrains.kotlinx.dataframe.api.groupBy
15
15
import org.jetbrains.kotlinx.dataframe.api.into
16
+ import org.jetbrains.kotlinx.dataframe.api.isEmpty
16
17
import org.jetbrains.kotlinx.dataframe.api.schema
17
18
import org.jetbrains.kotlinx.dataframe.api.toStr
18
19
import org.jetbrains.kotlinx.dataframe.ncol
@@ -282,6 +283,40 @@ class CsvTests {
282
283
df.columnNames() shouldBe listOf (" Column1" , " Column2" )
283
284
}
284
285
286
+ @Test
287
+ fun `read empty delimStr or CSV` () {
288
+ val emptyDelimStr = DataFrame .readDelimStr(" " )
289
+ emptyDelimStr shouldBe DataFrame .empty()
290
+
291
+ val emptyDelimFile = DataFrame .readDelim(File .createTempFile(" empty" , " csv" ).reader())
292
+ emptyDelimFile shouldBe DataFrame .empty()
293
+
294
+ val emptyCsvFile = DataFrame .readCSV(File .createTempFile(" empty" , " csv" ))
295
+ emptyCsvFile shouldBe DataFrame .empty()
296
+
297
+ val emptyCsvFileManualHeader = DataFrame .readCSV(
298
+ file = File .createTempFile(" empty" , " csv" ),
299
+ header = listOf (" a" , " b" , " c" ),
300
+ )
301
+ emptyCsvFileManualHeader.apply {
302
+ isEmpty() shouldBe true
303
+ columnNames() shouldBe listOf (" a" , " b" , " c" )
304
+ columnTypes() shouldBe listOf (typeOf<String >(), typeOf<String >(), typeOf<String >())
305
+ }
306
+
307
+ val emptyCsvFileWithHeader = DataFrame .readCSV(
308
+ file = File .createTempFile(" empty" , " csv" ).also { it.writeText(" a,b,c" ) },
309
+ )
310
+ emptyCsvFileWithHeader.apply {
311
+ isEmpty() shouldBe true
312
+ columnNames() shouldBe listOf (" a" , " b" , " c" )
313
+ columnTypes() shouldBe listOf (typeOf<String >(), typeOf<String >(), typeOf<String >())
314
+ }
315
+
316
+ val emptyTsvStr = DataFrame .readTSV(File .createTempFile(" empty" , " tsv" ))
317
+ emptyTsvStr shouldBe DataFrame .empty()
318
+ }
319
+
285
320
companion object {
286
321
private val simpleCsv = testCsv(" testCSV" )
287
322
private val csvWithFrenchLocale = testCsv(" testCSVwithFrenchLocale" )
0 commit comments