diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/csv.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/csv.kt index 6b13133ba8..94623b24e3 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/csv.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/csv.kt @@ -57,8 +57,8 @@ public class CSV(private val delimiter: Char = ',') : SupportedDataFrameFormat { } public enum class CSVType(public val format: CSVFormat) { - DEFAULT(CSVFormat.DEFAULT.withAllowMissingColumnNames().withIgnoreSurroundingSpaces()), - TDF(CSVFormat.TDF.withAllowMissingColumnNames()) + DEFAULT(CSVFormat.DEFAULT.builder().setAllowMissingColumnNames(true).setIgnoreSurroundingSpaces(true).build()), + TDF(CSVFormat.TDF.builder().setAllowMissingColumnNames(true).build()) } private val defaultCharset = Charsets.UTF_8 @@ -73,11 +73,15 @@ internal fun isCompressed(url: URL) = isCompressed(url.path) @Interpretable("ReadDelimStr") public fun DataFrame.Companion.readDelimStr( text: String, + delimiter: Char = ',', colTypes: Map = mapOf(), skipLines: Int = 0, readLines: Int? = null, ): DataFrame<*> = - StringReader(text).use { readDelim(it, CSVType.DEFAULT.format.withHeader(), colTypes, skipLines, readLines) } + StringReader(text).use { + val format = CSVType.DEFAULT.format.builder().setHeader().setDelimiter(delimiter).build() + readDelim(it, format, colTypes, skipLines, readLines) + } public fun DataFrame.Companion.read( fileOrUrl: String, @@ -212,7 +216,7 @@ public fun asURL(fileOrUrl: String): URL = ( ).toURL() private fun getFormat(type: CSVType, delimiter: Char, header: List, duplicate: Boolean): CSVFormat = - type.format.withDelimiter(delimiter).withHeader(*header.toTypedArray()).withAllowDuplicateHeaderNames(duplicate) + type.format.builder().setDelimiter(delimiter).setHeader(*header.toTypedArray()).setAllowMissingColumnNames(duplicate).build() public fun DataFrame.Companion.readDelim( inStream: InputStream, @@ -268,7 +272,7 @@ public fun ColType.toType(): KClass = when (this) { public fun DataFrame.Companion.readDelim( reader: Reader, - format: CSVFormat = CSVFormat.DEFAULT.withHeader(), + format: CSVFormat = CSVFormat.DEFAULT.builder().setHeader().build(), colTypes: Map = mapOf(), skipLines: Int = 0, readLines: Int? = null, diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/io/CsvTests.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/io/CsvTests.kt index e2aca14eda..58ed282f7b 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/io/CsvTests.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/io/CsvTests.kt @@ -242,7 +242,7 @@ class CsvTests { ) df.writeCSV( "src/test/resources/without_header.csv", - CSVFormat.DEFAULT.withSkipHeaderRecord(), + CSVFormat.DEFAULT.builder().setSkipHeaderRecord(true).build(), ) val producedFile = File("src/test/resources/without_header.csv") producedFile.exists() shouldBe true @@ -258,6 +258,16 @@ class CsvTests { df shouldBe DataFrame.readCSV("../data/jetbrains repositories.csv") } + @Test + fun `readDelimStr delimiter`() { + val tsv = """ + a b c + 1 2 3 + """.trimIndent() + val df = DataFrame.readDelimStr(tsv, '\t') + df shouldBe dataFrameOf("a", "b", "c")(1, 2, 3) + } + companion object { private val simpleCsv = testCsv("testCSV") private val csvWithFrenchLocale = testCsv("testCSVwithFrenchLocale") diff --git a/docs/StardustDocs/topics/write.md b/docs/StardustDocs/topics/write.md index a3c590fea1..aef2404fff 100644 --- a/docs/StardustDocs/topics/write.md +++ b/docs/StardustDocs/topics/write.md @@ -21,7 +21,8 @@ df.writeCSV(file) ```kotlin -val csvStr = df.toCsv(CSVFormat.DEFAULT.withDelimiter(';').withRecordSeparator(System.lineSeparator())) +val format = CSVFormat.DEFAULT.builder().setDelimiter(';').setRecordSeparator(System.lineSeparator()).build() +val csvStr = df.toCsv(format) ``` @@ -104,8 +105,10 @@ val wb = WorkbookFactory.create(true) // Create different sheets from different data frames in the workbook val allPersonsSheet = df.writeExcel(wb, sheetName = "allPersons") -val happyPersonsSheet = df.filter { person -> person.isHappy }.remove("isHappy").writeExcel(wb, sheetName = "happyPersons") -val unhappyPersonsSheet = df.filter { person -> !person.isHappy }.remove("isHappy").writeExcel(wb, sheetName = "unhappyPersons") +val happyPersonsSheet = + df.filter { person -> person.isHappy }.remove("isHappy").writeExcel(wb, sheetName = "happyPersons") +val unhappyPersonsSheet = + df.filter { person -> !person.isHappy }.remove("isHappy").writeExcel(wb, sheetName = "unhappyPersons") // Do anything you want by POI listOf(happyPersonsSheet, unhappyPersonsSheet).forEach { setStyles(it) } @@ -125,9 +128,11 @@ Add new sheets without using Apache POI directly by using a parameter to keep us // Create a new Excel workbook with a single sheet called "allPersons", replacing the file if it already exists -> Current sheets: allPersons df.writeExcel(file, sheetName = "allPersons") // Add a new sheet to the previous file without replacing it, by setting keepFile = true -> Current sheets: allPersons, happyPersons -df.filter { person -> person.isHappy }.remove("isHappy").writeExcel(file, sheetName = "happyPersons", keepFile = true) +df.filter { person -> person.isHappy }.remove("isHappy") + .writeExcel(file, sheetName = "happyPersons", keepFile = true) // Add a new sheet to the previous file without replacing it, by setting keepFile = true -> Current sheets: allPersons, happyPersons, unhappyPersons -df.filter { person -> !person.isHappy }.remove("isHappy").writeExcel(file, sheetName = "unhappyPersons", keepFile = true) +df.filter { person -> !person.isHappy }.remove("isHappy") + .writeExcel(file, sheetName = "unhappyPersons", keepFile = true) ``` @@ -203,7 +208,7 @@ df.arrowWriter( // Specify mismatch subscriber mismatchSubscriber = writeMismatchMessage, -).use { writer: ArrowWriter -> + ).use { writer: ArrowWriter -> // Save to any format and sink, like in the previous example writer.writeArrowFeather(file) diff --git a/plugins/kotlin-dataframe/src/org/jetbrains/kotlinx/dataframe/plugin/impl/api/read.kt b/plugins/kotlin-dataframe/src/org/jetbrains/kotlinx/dataframe/plugin/impl/api/read.kt index affa68fa5d..2191b790e8 100644 --- a/plugins/kotlin-dataframe/src/org/jetbrains/kotlinx/dataframe/plugin/impl/api/read.kt +++ b/plugins/kotlin-dataframe/src/org/jetbrains/kotlinx/dataframe/plugin/impl/api/read.kt @@ -90,9 +90,10 @@ private fun resolveFile(resolutionPath: String?, path: String): File? { internal class ReadDelimStr : AbstractInterpreter() { val Arguments.text: String by arg() + val Arguments.delimiter: Char by arg(defaultValue = Present(',')) override fun Arguments.interpret(): PluginDataFrameSchema { - return DataFrame.readDelimStr(text).schema().toPluginDataFrameSchema() + return DataFrame.readDelimStr(text, delimiter).schema().toPluginDataFrameSchema() } } diff --git a/plugins/kotlin-dataframe/testData/box/diff.fir.ir.txt b/plugins/kotlin-dataframe/testData/box/diff.fir.ir.txt index ea9c6ca73c..ec989bd535 100644 --- a/plugins/kotlin-dataframe/testData/box/diff.fir.ir.txt +++ b/plugins/kotlin-dataframe/testData/box/diff.fir.ir.txt @@ -49,7 +49,7 @@ FILE fqName:org.jetbrains.kotlinx.dataframe fileName:/diff.kt FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String BLOCK_BODY VAR name:df type:org.jetbrains.kotlinx.dataframe.DataFrame<*> [val] - CALL 'public final fun readDelimStr (text: kotlin.String, colTypes: kotlin.collections.Map, skipLines: kotlin.Int, readLines: kotlin.Int?): org.jetbrains.kotlinx.dataframe.DataFrame<*> declared in org.jetbrains.kotlinx.dataframe.io' type=org.jetbrains.kotlinx.dataframe.DataFrame<*> origin=null + CALL 'public final fun readDelimStr (text: kotlin.String, delimiter: kotlin.Char, colTypes: kotlin.collections.Map, skipLines: kotlin.Int, readLines: kotlin.Int?): org.jetbrains.kotlinx.dataframe.DataFrame<*> declared in org.jetbrains.kotlinx.dataframe.io' type=org.jetbrains.kotlinx.dataframe.DataFrame<*> origin=null $receiver: GET_OBJECT 'CLASS OBJECT name:Companion modality:FINAL visibility:public [companion] superTypes:[kotlin.Any]' type=org.jetbrains.kotlinx.dataframe.DataFrame.Companion text: CALL 'public final fun trimIndent (): kotlin.String declared in kotlin.text' type=kotlin.String origin=null $receiver: CONST String type=kotlin.String value="\n char,level,race,charclass,zone,guild,timestamp\n 59425,1,Orc,Rogue,Orgrimmar,165,01/01/08 00:02:04\n 65494,9,Orc,Hunter,Durotar,-1,01/01/08 00:02:04\n " diff --git a/plugins/kotlin-dataframe/testData/box/flexibleReturnType.fir.ir.txt b/plugins/kotlin-dataframe/testData/box/flexibleReturnType.fir.ir.txt index 6af717f6d7..621b5c25b5 100644 --- a/plugins/kotlin-dataframe/testData/box/flexibleReturnType.fir.ir.txt +++ b/plugins/kotlin-dataframe/testData/box/flexibleReturnType.fir.ir.txt @@ -27,7 +27,7 @@ FILE fqName:org.jetbrains.kotlinx.dataframe fileName:/flexibleReturnType.kt FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String BLOCK_BODY VAR name:df type:org.jetbrains.kotlinx.dataframe.DataFrame<*> [val] - CALL 'public final fun readDelimStr (text: kotlin.String, colTypes: kotlin.collections.Map, skipLines: kotlin.Int, readLines: kotlin.Int?): org.jetbrains.kotlinx.dataframe.DataFrame<*> declared in org.jetbrains.kotlinx.dataframe.io' type=org.jetbrains.kotlinx.dataframe.DataFrame<*> origin=null + CALL 'public final fun readDelimStr (text: kotlin.String, delimiter: kotlin.Char, colTypes: kotlin.collections.Map, skipLines: kotlin.Int, readLines: kotlin.Int?): org.jetbrains.kotlinx.dataframe.DataFrame<*> declared in org.jetbrains.kotlinx.dataframe.io' type=org.jetbrains.kotlinx.dataframe.DataFrame<*> origin=null $receiver: GET_OBJECT 'CLASS OBJECT name:Companion modality:FINAL visibility:public [companion] superTypes:[kotlin.Any]' type=org.jetbrains.kotlinx.dataframe.DataFrame.Companion text: CALL 'public final fun trimIndent (): kotlin.String declared in kotlin.text' type=kotlin.String origin=null $receiver: CONST String type=kotlin.String value="\n char,level,race,charclass,zone,guild,timestamp\n 59425,1,Orc,Rogue,Orgrimmar,165,01/01/08 00:02:04\n 65494,9,Orc,Hunter,Durotar,-1,01/01/08 00:02:04\n " diff --git a/plugins/kotlin-dataframe/testData/box/readDelimStr_delimiter.fir.ir.txt b/plugins/kotlin-dataframe/testData/box/readDelimStr_delimiter.fir.ir.txt new file mode 100644 index 0000000000..a826dc35c5 --- /dev/null +++ b/plugins/kotlin-dataframe/testData/box/readDelimStr_delimiter.fir.ir.txt @@ -0,0 +1,230 @@ +FILE fqName: fileName:/readDelimStr_delimiter.kt + FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String + BLOCK_BODY + VAR name:tsv type:kotlin.String [val] + CONST String type=kotlin.String value="\n a\tb\tc\n 1\t2\t3\n " + VAR name:df type:org.jetbrains.kotlinx.dataframe.DataFrame<.box..ReadDelimStr_21> [val] + CALL 'public final fun let (block: kotlin.Function1): R of kotlin.let declared in kotlin' type=org.jetbrains.kotlinx.dataframe.DataFrame<.box..ReadDelimStr_21> origin=null + : org.jetbrains.kotlinx.dataframe.DataFrame.Companion + : org.jetbrains.kotlinx.dataframe.DataFrame<.box..ReadDelimStr_21> + $receiver: GET_OBJECT 'CLASS OBJECT name:Companion modality:FINAL visibility:public [companion] superTypes:[kotlin.Any]' type=org.jetbrains.kotlinx.dataframe.DataFrame.Companion + block: FUN_EXPR type=kotlin.Function1.box..ReadDelimStr_21>> origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:org.jetbrains.kotlinx.dataframe.DataFrame.Companion) returnType:org.jetbrains.kotlinx.dataframe.DataFrame<.box..ReadDelimStr_21> + VALUE_PARAMETER name:it index:0 type:org.jetbrains.kotlinx.dataframe.DataFrame.Companion + BLOCK_BODY + CLASS CLASS name:ReadDelimStr_21I modality:ABSTRACT visibility:local superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.box..ReadDelimStr_21I + CONSTRUCTOR GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.DataFramePlugin] visibility:public <> () returnType:.box..ReadDelimStr_21I [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:ReadDelimStr_21I modality:ABSTRACT visibility:local superTypes:[kotlin.Any]' + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + PROPERTY GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.TokenGenerator.Key] name:a visibility:public modality:ABSTRACT [val] + annotations: + Order(order = 0) + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:ABSTRACT <> ($this:.box..ReadDelimStr_21I) returnType:kotlin.Int? + correspondingProperty: PROPERTY GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.TokenGenerator.Key] name:a visibility:public modality:ABSTRACT [val] + $this: VALUE_PARAMETER name: type:.box..ReadDelimStr_21I + PROPERTY GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.TokenGenerator.Key] name:b visibility:public modality:ABSTRACT [val] + annotations: + Order(order = 1) + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:ABSTRACT <> ($this:.box..ReadDelimStr_21I) returnType:kotlin.Int? + correspondingProperty: PROPERTY GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.TokenGenerator.Key] name:b visibility:public modality:ABSTRACT [val] + $this: VALUE_PARAMETER name: type:.box..ReadDelimStr_21I + PROPERTY GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.TokenGenerator.Key] name:c visibility:public modality:ABSTRACT [val] + annotations: + Order(order = 2) + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:ABSTRACT <> ($this:.box..ReadDelimStr_21I) returnType:kotlin.Int? + correspondingProperty: PROPERTY GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.TokenGenerator.Key] name:c visibility:public modality:ABSTRACT [val] + $this: VALUE_PARAMETER name: type:.box..ReadDelimStr_21I + CLASS CLASS name:Scope0 modality:FINAL visibility:local superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.box..Scope0 + PROPERTY GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.DataFramePlugin] name:c visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.Int? visibility:private [final] + FUN GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.DataFramePlugin] name: visibility:public modality:FINAL <> ($this:.box..Scope0, $receiver:org.jetbrains.kotlinx.dataframe.DataRow<.box..ReadDelimStr_21I>) returnType:kotlin.Int? + annotations: + JvmName(name = "ReadDelimStr_21I_c") + correspondingProperty: PROPERTY GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.DataFramePlugin] name:c visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.box..Scope0 + $receiver: VALUE_PARAMETER name: type:org.jetbrains.kotlinx.dataframe.DataRow<.box..ReadDelimStr_21I> + BLOCK_BODY + RETURN type=kotlin.Int? from='public final fun (): kotlin.Int? declared in .box..Scope0' + TYPE_OP type=kotlin.Int? origin=CAST typeOperand=kotlin.Int? + CALL 'public abstract fun get (name: kotlin.String): kotlin.Any? declared in org.jetbrains.kotlinx.dataframe.DataRow' type=kotlin.Any? origin=null + $this: GET_VAR ': org.jetbrains.kotlinx.dataframe.DataRow<.box..ReadDelimStr_21I> declared in .box..Scope0.' type=org.jetbrains.kotlinx.dataframe.DataRow<.box..ReadDelimStr_21I> origin=null + name: CONST String type=kotlin.String value="c" + PROPERTY GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.DataFramePlugin] name:c visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:c type:org.jetbrains.kotlinx.dataframe.DataColumn visibility:private [final] + FUN GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.DataFramePlugin] name: visibility:public modality:FINAL <> ($this:.box..Scope0, $receiver:org.jetbrains.kotlinx.dataframe.ColumnsContainer<.box..ReadDelimStr_21I>) returnType:org.jetbrains.kotlinx.dataframe.DataColumn + annotations: + JvmName(name = "ReadDelimStr_21I_c") + correspondingProperty: PROPERTY GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.DataFramePlugin] name:c visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.box..Scope0 + $receiver: VALUE_PARAMETER name: type:org.jetbrains.kotlinx.dataframe.ColumnsContainer<.box..ReadDelimStr_21I> + BLOCK_BODY + RETURN type=org.jetbrains.kotlinx.dataframe.DataColumn from='public final fun (): org.jetbrains.kotlinx.dataframe.DataColumn declared in .box..Scope0' + TYPE_OP type=org.jetbrains.kotlinx.dataframe.DataColumn origin=CAST typeOperand=org.jetbrains.kotlinx.dataframe.DataColumn + CALL 'public open fun get (columnName: kotlin.String): org.jetbrains.kotlinx.dataframe.DataColumn<*> declared in org.jetbrains.kotlinx.dataframe.ColumnsContainer' type=kotlin.Any? origin=null + $this: GET_VAR ': org.jetbrains.kotlinx.dataframe.ColumnsContainer<.box..ReadDelimStr_21I> declared in .box..Scope0.' type=org.jetbrains.kotlinx.dataframe.ColumnsContainer<.box..ReadDelimStr_21I> origin=null + columnName: CONST String type=kotlin.String value="c" + PROPERTY GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.DataFramePlugin] name:b visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:b type:kotlin.Int? visibility:private [final] + FUN GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.DataFramePlugin] name: visibility:public modality:FINAL <> ($this:.box..Scope0, $receiver:org.jetbrains.kotlinx.dataframe.DataRow<.box..ReadDelimStr_21I>) returnType:kotlin.Int? + annotations: + JvmName(name = "ReadDelimStr_21I_b") + correspondingProperty: PROPERTY GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.DataFramePlugin] name:b visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.box..Scope0 + $receiver: VALUE_PARAMETER name: type:org.jetbrains.kotlinx.dataframe.DataRow<.box..ReadDelimStr_21I> + BLOCK_BODY + RETURN type=kotlin.Int? from='public final fun (): kotlin.Int? declared in .box..Scope0' + TYPE_OP type=kotlin.Int? origin=CAST typeOperand=kotlin.Int? + CALL 'public abstract fun get (name: kotlin.String): kotlin.Any? declared in org.jetbrains.kotlinx.dataframe.DataRow' type=kotlin.Any? origin=null + $this: GET_VAR ': org.jetbrains.kotlinx.dataframe.DataRow<.box..ReadDelimStr_21I> declared in .box..Scope0.' type=org.jetbrains.kotlinx.dataframe.DataRow<.box..ReadDelimStr_21I> origin=null + name: CONST String type=kotlin.String value="b" + PROPERTY GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.DataFramePlugin] name:b visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:b type:org.jetbrains.kotlinx.dataframe.DataColumn visibility:private [final] + FUN GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.DataFramePlugin] name: visibility:public modality:FINAL <> ($this:.box..Scope0, $receiver:org.jetbrains.kotlinx.dataframe.ColumnsContainer<.box..ReadDelimStr_21I>) returnType:org.jetbrains.kotlinx.dataframe.DataColumn + annotations: + JvmName(name = "ReadDelimStr_21I_b") + correspondingProperty: PROPERTY GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.DataFramePlugin] name:b visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.box..Scope0 + $receiver: VALUE_PARAMETER name: type:org.jetbrains.kotlinx.dataframe.ColumnsContainer<.box..ReadDelimStr_21I> + BLOCK_BODY + RETURN type=org.jetbrains.kotlinx.dataframe.DataColumn from='public final fun (): org.jetbrains.kotlinx.dataframe.DataColumn declared in .box..Scope0' + TYPE_OP type=org.jetbrains.kotlinx.dataframe.DataColumn origin=CAST typeOperand=org.jetbrains.kotlinx.dataframe.DataColumn + CALL 'public open fun get (columnName: kotlin.String): org.jetbrains.kotlinx.dataframe.DataColumn<*> declared in org.jetbrains.kotlinx.dataframe.ColumnsContainer' type=kotlin.Any? origin=null + $this: GET_VAR ': org.jetbrains.kotlinx.dataframe.ColumnsContainer<.box..ReadDelimStr_21I> declared in .box..Scope0.' type=org.jetbrains.kotlinx.dataframe.ColumnsContainer<.box..ReadDelimStr_21I> origin=null + columnName: CONST String type=kotlin.String value="b" + PROPERTY GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.DataFramePlugin] name:a visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.Int? visibility:private [final] + FUN GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.DataFramePlugin] name: visibility:public modality:FINAL <> ($this:.box..Scope0, $receiver:org.jetbrains.kotlinx.dataframe.DataRow<.box..ReadDelimStr_21I>) returnType:kotlin.Int? + annotations: + JvmName(name = "ReadDelimStr_21I_a") + correspondingProperty: PROPERTY GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.DataFramePlugin] name:a visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.box..Scope0 + $receiver: VALUE_PARAMETER name: type:org.jetbrains.kotlinx.dataframe.DataRow<.box..ReadDelimStr_21I> + BLOCK_BODY + RETURN type=kotlin.Int? from='public final fun (): kotlin.Int? declared in .box..Scope0' + TYPE_OP type=kotlin.Int? origin=CAST typeOperand=kotlin.Int? + CALL 'public abstract fun get (name: kotlin.String): kotlin.Any? declared in org.jetbrains.kotlinx.dataframe.DataRow' type=kotlin.Any? origin=null + $this: GET_VAR ': org.jetbrains.kotlinx.dataframe.DataRow<.box..ReadDelimStr_21I> declared in .box..Scope0.' type=org.jetbrains.kotlinx.dataframe.DataRow<.box..ReadDelimStr_21I> origin=null + name: CONST String type=kotlin.String value="a" + PROPERTY GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.DataFramePlugin] name:a visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:a type:org.jetbrains.kotlinx.dataframe.DataColumn visibility:private [final] + FUN GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.DataFramePlugin] name: visibility:public modality:FINAL <> ($this:.box..Scope0, $receiver:org.jetbrains.kotlinx.dataframe.ColumnsContainer<.box..ReadDelimStr_21I>) returnType:org.jetbrains.kotlinx.dataframe.DataColumn + annotations: + JvmName(name = "ReadDelimStr_21I_a") + correspondingProperty: PROPERTY GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.DataFramePlugin] name:a visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.box..Scope0 + $receiver: VALUE_PARAMETER name: type:org.jetbrains.kotlinx.dataframe.ColumnsContainer<.box..ReadDelimStr_21I> + BLOCK_BODY + RETURN type=org.jetbrains.kotlinx.dataframe.DataColumn from='public final fun (): org.jetbrains.kotlinx.dataframe.DataColumn declared in .box..Scope0' + TYPE_OP type=org.jetbrains.kotlinx.dataframe.DataColumn origin=CAST typeOperand=org.jetbrains.kotlinx.dataframe.DataColumn + CALL 'public open fun get (columnName: kotlin.String): org.jetbrains.kotlinx.dataframe.DataColumn<*> declared in org.jetbrains.kotlinx.dataframe.ColumnsContainer' type=kotlin.Any? origin=null + $this: GET_VAR ': org.jetbrains.kotlinx.dataframe.ColumnsContainer<.box..ReadDelimStr_21I> declared in .box..Scope0.' type=org.jetbrains.kotlinx.dataframe.ColumnsContainer<.box..ReadDelimStr_21I> origin=null + columnName: CONST String type=kotlin.String value="a" + CONSTRUCTOR GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.DataFramePlugin] visibility:public <> () returnType:.box..Scope0 [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Scope0 modality:FINAL visibility:local superTypes:[kotlin.Any]' + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:ReadDelimStr_21 modality:ABSTRACT visibility:local superTypes:[.box..ReadDelimStr_21I] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.box..ReadDelimStr_21 + CONSTRUCTOR GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.DataFramePlugin] visibility:public <> () returnType:.box..ReadDelimStr_21 [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in .box..ReadDelimStr_21I' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:ReadDelimStr_21 modality:ABSTRACT visibility:local superTypes:[.box..ReadDelimStr_21I]' + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in .box..ReadDelimStr_21I + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in .box..ReadDelimStr_21I + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in .box..ReadDelimStr_21I + $this: VALUE_PARAMETER name: type:kotlin.Any + PROPERTY FAKE_OVERRIDE name:a visibility:public modality:ABSTRACT [fake_override,val] + annotations: + Order(order = 0) + overridden: + public abstract a: kotlin.Int? declared in .box..ReadDelimStr_21I + FUN FAKE_OVERRIDE name: visibility:public modality:ABSTRACT <> ($this:.box..ReadDelimStr_21I) returnType:kotlin.Int? [fake_override] + correspondingProperty: PROPERTY FAKE_OVERRIDE name:a visibility:public modality:ABSTRACT [fake_override,val] + overridden: + public abstract fun (): kotlin.Int? declared in .box..ReadDelimStr_21I + $this: VALUE_PARAMETER name: type:.box..ReadDelimStr_21I + PROPERTY FAKE_OVERRIDE name:b visibility:public modality:ABSTRACT [fake_override,val] + annotations: + Order(order = 1) + overridden: + public abstract b: kotlin.Int? declared in .box..ReadDelimStr_21I + FUN FAKE_OVERRIDE name: visibility:public modality:ABSTRACT <> ($this:.box..ReadDelimStr_21I) returnType:kotlin.Int? [fake_override] + correspondingProperty: PROPERTY FAKE_OVERRIDE name:b visibility:public modality:ABSTRACT [fake_override,val] + overridden: + public abstract fun (): kotlin.Int? declared in .box..ReadDelimStr_21I + $this: VALUE_PARAMETER name: type:.box..ReadDelimStr_21I + PROPERTY FAKE_OVERRIDE name:c visibility:public modality:ABSTRACT [fake_override,val] + annotations: + Order(order = 2) + overridden: + public abstract c: kotlin.Int? declared in .box..ReadDelimStr_21I + FUN FAKE_OVERRIDE name: visibility:public modality:ABSTRACT <> ($this:.box..ReadDelimStr_21I) returnType:kotlin.Int? [fake_override] + correspondingProperty: PROPERTY FAKE_OVERRIDE name:c visibility:public modality:ABSTRACT [fake_override,val] + overridden: + public abstract fun (): kotlin.Int? declared in .box..ReadDelimStr_21I + $this: VALUE_PARAMETER name: type:.box..ReadDelimStr_21I + PROPERTY GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.TokenGenerator.Key] name:scope0 visibility:public modality:ABSTRACT [var] + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:ABSTRACT <> ($this:.box..ReadDelimStr_21) returnType:.box..Scope0 + correspondingProperty: PROPERTY GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.TokenGenerator.Key] name:scope0 visibility:public modality:ABSTRACT [var] + $this: VALUE_PARAMETER name: type:.box..ReadDelimStr_21 + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:ABSTRACT <> ($this:.box..ReadDelimStr_21, :.box..Scope0) returnType:kotlin.Unit + correspondingProperty: PROPERTY GENERATED[org.jetbrains.kotlinx.dataframe.plugin.extensions.TokenGenerator.Key] name:scope0 visibility:public modality:ABSTRACT [var] + $this: VALUE_PARAMETER name: type:.box..ReadDelimStr_21 + VALUE_PARAMETER name: index:0 type:.box..Scope0 + RETURN type=kotlin.Nothing from='local final fun (it: org.jetbrains.kotlinx.dataframe.DataFrame.Companion): org.jetbrains.kotlinx.dataframe.DataFrame<.box..ReadDelimStr_21> declared in .box' + CALL 'public final fun readDelimStr (text: kotlin.String, delimiter: kotlin.Char, colTypes: kotlin.collections.Map, skipLines: kotlin.Int, readLines: kotlin.Int?): org.jetbrains.kotlinx.dataframe.DataFrame<*> declared in org.jetbrains.kotlinx.dataframe.io' type=org.jetbrains.kotlinx.dataframe.DataFrame<.box..ReadDelimStr_21> origin=null + $receiver: GET_VAR 'it: org.jetbrains.kotlinx.dataframe.DataFrame.Companion declared in .box.' type=org.jetbrains.kotlinx.dataframe.DataFrame.Companion origin=null + text: GET_VAR 'val tsv: kotlin.String declared in .box' type=kotlin.String origin=null + delimiter: CONST Char type=kotlin.Char value='\t' + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public final fun (): org.jetbrains.kotlinx.dataframe.DataColumn declared in .box..Scope0' type=org.jetbrains.kotlinx.dataframe.DataColumn origin=GET_PROPERTY + $this: CONSTRUCTOR_CALL 'public constructor () declared in .box..Scope0' type=.box..Scope0 origin=null + $receiver: GET_VAR 'val df: org.jetbrains.kotlinx.dataframe.DataFrame<.box..ReadDelimStr_21> declared in .box' type=org.jetbrains.kotlinx.dataframe.DataFrame<.box..ReadDelimStr_21> origin=null + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public final fun (): org.jetbrains.kotlinx.dataframe.DataColumn declared in .box..Scope0' type=org.jetbrains.kotlinx.dataframe.DataColumn origin=GET_PROPERTY + $this: CONSTRUCTOR_CALL 'public constructor () declared in .box..Scope0' type=.box..Scope0 origin=null + $receiver: GET_VAR 'val df: org.jetbrains.kotlinx.dataframe.DataFrame<.box..ReadDelimStr_21> declared in .box' type=org.jetbrains.kotlinx.dataframe.DataFrame<.box..ReadDelimStr_21> origin=null + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public final fun (): org.jetbrains.kotlinx.dataframe.DataColumn declared in .box..Scope0' type=org.jetbrains.kotlinx.dataframe.DataColumn origin=GET_PROPERTY + $this: CONSTRUCTOR_CALL 'public constructor () declared in .box..Scope0' type=.box..Scope0 origin=null + $receiver: GET_VAR 'val df: org.jetbrains.kotlinx.dataframe.DataFrame<.box..ReadDelimStr_21> declared in .box' type=org.jetbrains.kotlinx.dataframe.DataFrame<.box..ReadDelimStr_21> origin=null + RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' + CONST String type=kotlin.String value="OK" diff --git a/plugins/kotlin-dataframe/testData/box/readDelimStr_delimiter.fir.txt b/plugins/kotlin-dataframe/testData/box/readDelimStr_delimiter.fir.txt new file mode 100644 index 0000000000..4fbf59fc5a --- /dev/null +++ b/plugins/kotlin-dataframe/testData/box/readDelimStr_delimiter.fir.txt @@ -0,0 +1,61 @@ +FILE: readDelimStr_delimiter.kt + public final fun box(): R|kotlin/String| { + lval tsv: R|kotlin/String| = String( + a b c + 1 2 3 + ) + lval df: R|org/jetbrains/kotlinx/dataframe/DataFrame</ReadDelimStr_21>| = Q|org/jetbrains/kotlinx/dataframe/DataFrame|.R|kotlin/let|/ReadDelimStr_21>|>( = fun (it: R|org/jetbrains/kotlinx/dataframe/DataFrame.Companion|): R|org/jetbrains/kotlinx/dataframe/DataFrame</ReadDelimStr_21>| { + local abstract class ReadDelimStr_21I : R|kotlin/Any| { + @R|org/jetbrains/kotlinx/dataframe/annotations/Order|(order = Int(2)) public abstract val c: R|kotlin/Int?| + public get(): R|kotlin/Int?| + + @R|org/jetbrains/kotlinx/dataframe/annotations/Order|(order = Int(1)) public abstract val b: R|kotlin/Int?| + public get(): R|kotlin/Int?| + + @R|org/jetbrains/kotlinx/dataframe/annotations/Order|(order = Int(0)) public abstract val a: R|kotlin/Int?| + public get(): R|kotlin/Int?| + + public constructor(): R|/ReadDelimStr_21I| + + } + + local final class Scope0 : R|kotlin/Any| { + public final val R|org/jetbrains/kotlinx/dataframe/DataRow</ReadDelimStr_21I>|.c: R|kotlin/Int?| + public get(): R|kotlin/Int?| + + public final val R|org/jetbrains/kotlinx/dataframe/ColumnsContainer</ReadDelimStr_21I>|.c: R|org/jetbrains/kotlinx/dataframe/DataColumn| + public get(): R|org/jetbrains/kotlinx/dataframe/DataColumn| + + public final val R|org/jetbrains/kotlinx/dataframe/DataRow</ReadDelimStr_21I>|.b: R|kotlin/Int?| + public get(): R|kotlin/Int?| + + public final val R|org/jetbrains/kotlinx/dataframe/ColumnsContainer</ReadDelimStr_21I>|.b: R|org/jetbrains/kotlinx/dataframe/DataColumn| + public get(): R|org/jetbrains/kotlinx/dataframe/DataColumn| + + public final val R|org/jetbrains/kotlinx/dataframe/DataRow</ReadDelimStr_21I>|.a: R|kotlin/Int?| + public get(): R|kotlin/Int?| + + public final val R|org/jetbrains/kotlinx/dataframe/ColumnsContainer</ReadDelimStr_21I>|.a: R|org/jetbrains/kotlinx/dataframe/DataColumn| + public get(): R|org/jetbrains/kotlinx/dataframe/DataColumn| + + public constructor(): R|/Scope0| + + } + + local abstract class ReadDelimStr_21 : R|/ReadDelimStr_21I| { + public abstract var scope0: R|/Scope0| + public get(): R|/Scope0| + public set(value: R|/Scope0|): R|kotlin/Unit| + + public constructor(): R|/ReadDelimStr_21| + + } + + ^ R|/it|.R|org/jetbrains/kotlinx/dataframe/io/readDelimStr|(R|/tsv|, Char(9)) + } + ) + (this@R|/box|, R|/df|).R|/Scope0.a| + (this@R|/box|, R|/df|).R|/Scope0.b| + (this@R|/box|, R|/df|).R|/Scope0.c| + ^box String(OK) + } diff --git a/plugins/kotlin-dataframe/testData/box/readDelimStr_delimiter.kt b/plugins/kotlin-dataframe/testData/box/readDelimStr_delimiter.kt new file mode 100644 index 0000000000..73be1cd0ff --- /dev/null +++ b/plugins/kotlin-dataframe/testData/box/readDelimStr_delimiter.kt @@ -0,0 +1,15 @@ +import org.jetbrains.kotlinx.dataframe.api.* +import org.jetbrains.kotlinx.dataframe.io.* +import org.jetbrains.kotlinx.dataframe.* + +fun box(): String { + val tsv = """ + a b c + 1 2 3 + """ + val df = DataFrame.readDelimStr(tsv, '\t') + df.a + df.b + df.c + return "OK" +} diff --git a/plugins/kotlin-dataframe/tests-gen/org/jetbrains/kotlin/fir/dataframe/DataFrameBlackBoxCodegenTestGenerated.java b/plugins/kotlin-dataframe/tests-gen/org/jetbrains/kotlin/fir/dataframe/DataFrameBlackBoxCodegenTestGenerated.java index 168f830567..031def1b7e 100644 --- a/plugins/kotlin-dataframe/tests-gen/org/jetbrains/kotlin/fir/dataframe/DataFrameBlackBoxCodegenTestGenerated.java +++ b/plugins/kotlin-dataframe/tests-gen/org/jetbrains/kotlin/fir/dataframe/DataFrameBlackBoxCodegenTestGenerated.java @@ -225,6 +225,12 @@ public void testReadCSV() { runTest("testData/box/readCSV.kt"); } + @Test + @TestMetadata("readDelimStr_delimiter.kt") + public void testReadDelimStr_delimiter() { + runTest("testData/box/readDelimStr_delimiter.kt"); + } + @Test @TestMetadata("readJson.kt") public void testReadJson() { diff --git a/tests/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/Write.kt b/tests/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/Write.kt index 28274a96d3..87c153104b 100644 --- a/tests/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/Write.kt +++ b/tests/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/Write.kt @@ -46,7 +46,8 @@ class Write : TestBase() { @Test fun writeCsvStr() { // SampleStart - val csvStr = df.toCsv(CSVFormat.DEFAULT.withDelimiter(';').withRecordSeparator(System.lineSeparator())) + val format = CSVFormat.DEFAULT.builder().setDelimiter(';').setRecordSeparator(System.lineSeparator()).build() + val csvStr = df.toCsv(format) // SampleEnd csvStr shouldStartWith """ name;age;city;weight;isHappy @@ -116,8 +117,10 @@ class Write : TestBase() { // Create different sheets from different data frames in the workbook val allPersonsSheet = df.writeExcel(wb, sheetName = "allPersons") - val happyPersonsSheet = df.filter { person -> person.isHappy }.remove("isHappy").writeExcel(wb, sheetName = "happyPersons") - val unhappyPersonsSheet = df.filter { person -> !person.isHappy }.remove("isHappy").writeExcel(wb, sheetName = "unhappyPersons") + val happyPersonsSheet = + df.filter { person -> person.isHappy }.remove("isHappy").writeExcel(wb, sheetName = "happyPersons") + val unhappyPersonsSheet = + df.filter { person -> !person.isHappy }.remove("isHappy").writeExcel(wb, sheetName = "unhappyPersons") // Do anything you want by POI listOf(happyPersonsSheet, unhappyPersonsSheet).forEach { setStyles(it) } @@ -153,7 +156,7 @@ class Write : TestBase() { fun writeArrowPerSchema() { useTempFile { file -> val schemaJson = -"""{ + """{ "fields" : [ { "name" : "name", "nullable" : true, @@ -226,9 +229,11 @@ class Write : TestBase() { // Create a new Excel workbook with a single sheet called "allPersons", replacing the file if it already exists -> Current sheets: allPersons df.writeExcel(file, sheetName = "allPersons") // Add a new sheet to the previous file without replacing it, by setting keepFile = true -> Current sheets: allPersons, happyPersons - df.filter { person -> person.isHappy }.remove("isHappy").writeExcel(file, sheetName = "happyPersons", keepFile = true) + df.filter { person -> person.isHappy }.remove("isHappy") + .writeExcel(file, sheetName = "happyPersons", keepFile = true) // Add a new sheet to the previous file without replacing it, by setting keepFile = true -> Current sheets: allPersons, happyPersons, unhappyPersons - df.filter { person -> !person.isHappy }.remove("isHappy").writeExcel(file, sheetName = "unhappyPersons", keepFile = true) + df.filter { person -> !person.isHappy }.remove("isHappy") + .writeExcel(file, sheetName = "unhappyPersons", keepFile = true) // SampleEnd } }