Skip to content

Commit

Permalink
Update generated sources with recent changes
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jun 19, 2024
1 parent 47228e6 commit fff717d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String, ColType> = 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,
Expand Down Expand Up @@ -212,7 +216,7 @@ public fun asURL(fileOrUrl: String): URL = (
).toURL()

private fun getFormat(type: CSVType, delimiter: Char, header: List<String>, 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,
Expand Down Expand Up @@ -268,7 +272,7 @@ public fun ColType.toType(): KClass<out Any> = when (this) {

public fun DataFrame.Companion.readDelim(
reader: Reader,
format: CSVFormat = CSVFormat.DEFAULT.withHeader(),
format: CSVFormat = CSVFormat.DEFAULT.builder().setHeader().build(),
colTypes: Map<String, ColType> = mapOf(),
skipLines: Int = 0,
readLines: Int? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down

0 comments on commit fff717d

Please sign in to comment.