Skip to content

Commit b9310d5

Browse files
authored
Merge pull request #211 from vhuc/patch-1
Don't print header record in csv if requested
2 parents e0b27ba + e516fe2 commit b9310d5

File tree

2 files changed

+19
-1
lines changed
  • core/src
    • main/kotlin/org/jetbrains/kotlinx/dataframe/io
    • test/kotlin/org/jetbrains/kotlinx/dataframe/io

2 files changed

+19
-1
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/csv.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,9 @@ public fun AnyFrame.writeCSV(
332332
format: CSVFormat = CSVFormat.DEFAULT,
333333
) {
334334
format.print(writer).use { printer ->
335-
printer.printRecord(columnNames())
335+
if (format.getSkipHeaderRecord() == false) {
336+
printer.printRecord(columnNames())
337+
}
336338
forEach {
337339
val values = it.values.map {
338340
when (it) {

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/io/CsvTests.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,22 @@ class CsvTests {
214214
df.columnsCount() shouldBe 3
215215
df.rowsCount() shouldBe 2
216216
}
217+
218+
@Test
219+
fun `write csv whitout header produce correct file`() {
220+
val df = dataFrameOf("a", "b", "c")(
221+
1, 2, 3,
222+
1, 3, 2
223+
)
224+
df.writeCSV(
225+
"src/test/resources/without_header.csv",
226+
CSVFormat.DEFAULT.withSkipHeaderRecord()
227+
)
228+
val producedFile = File("src/test/resources/without_header.csv")
229+
producedFile.exists() shouldBe true
230+
producedFile.readText() shouldBe "a,b,c\r\n1,2,3\r\n1,3,2\r\n"
231+
producedFile.delete()
232+
}
217233

218234
companion object {
219235
private val simpleCsv = testCsv("testCSV")

0 commit comments

Comments
 (0)