Skip to content

Commit d50a246

Browse files
Automated commit of generated code
1 parent 05235f4 commit d50a246

File tree

4 files changed

+50
-15
lines changed

4 files changed

+50
-15
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import java.math.BigDecimal
5757
import java.math.BigInteger
5858
import java.net.URL
5959
import java.nio.charset.Charset
60+
import java.nio.file.Path
6061
import java.util.zip.GZIPInputStream
6162
import kotlin.reflect.KClass
6263
import kotlin.reflect.KType
@@ -73,6 +74,10 @@ public class CSV(private val delimiter: Char = ',') : SupportedDataFrameFormat {
7374
override fun readDataFrame(file: File, header: List<String>): AnyFrame =
7475
DataFrame.readCSV(file = file, delimiter = delimiter, header = header)
7576

77+
override fun readDataFrame(path: Path, header: List<String>): AnyFrame =
78+
// core CSV impl is deprecated, delegate via File to preserve module boundaries
79+
DataFrame.readCSV(file = path.toFile(), delimiter = delimiter, header = header)
80+
7681
override fun acceptsExtension(ext: String): Boolean = ext == "csv"
7782

7883
override fun acceptsSample(sample: SupportedFormatSample): Boolean = true // Extension is enough

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/guess.kt

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import java.io.File
1616
import java.io.FileNotFoundException
1717
import java.io.InputStream
1818
import java.net.URL
19+
import java.nio.file.Path
1920
import java.util.ServiceLoader
21+
import kotlin.io.path.extension
2022
import kotlin.reflect.KType
2123

2224
public sealed interface SupportedFormat {
@@ -37,6 +39,9 @@ public sealed interface SupportedFormatSample {
3739
@JvmInline
3840
public value class DataFile(public val sampleFile: File) : SupportedFormatSample
3941

42+
@JvmInline
43+
public value class DataPath(public val samplePath: Path) : SupportedFormatSample
44+
4045
@JvmInline
4146
public value class DataUrl(public val sampleUrl: URL) : SupportedFormatSample
4247

@@ -56,7 +61,10 @@ public sealed interface SupportedFormatSample {
5661
public interface SupportedDataFrameFormat : SupportedFormat {
5762
public fun readDataFrame(stream: InputStream, header: List<String> = emptyList()): DataFrame<*>
5863

59-
public fun readDataFrame(file: File, header: List<String> = emptyList()): DataFrame<*>
64+
public fun readDataFrame(file: File, header: List<String> = emptyList()): DataFrame<*> =
65+
readDataFrame(file.toPath(), header)
66+
67+
public fun readDataFrame(path: Path, header: List<String> = emptyList()): DataFrame<*>
6068
}
6169

6270
/**
@@ -137,10 +145,10 @@ internal fun guessFormatForExtension(
137145
): SupportedFormat? = formats.firstOrNull { it.acceptsExtension(ext) && (sample == null || it.acceptsSample(sample)) }
138146

139147
internal fun guessFormat(
140-
file: File,
148+
path: Path,
141149
formats: List<SupportedFormat> = supportedFormats,
142-
sample: SupportedFormatSample.DataFile? = SupportedFormatSample.DataFile(file),
143-
): SupportedFormat? = guessFormatForExtension(file.extension.lowercase(), formats, sample = sample)
150+
sample: SupportedFormatSample.DataPath? = SupportedFormatSample.DataPath(path),
151+
): SupportedFormat? = guessFormatForExtension(path.extension.lowercase(), formats, sample = sample)
144152

145153
internal fun guessFormat(
146154
url: URL,
@@ -223,15 +231,15 @@ internal fun DataFrame.Companion.read(
223231
}
224232

225233
internal fun DataFrame.Companion.read(
226-
file: File,
234+
path: Path,
227235
format: SupportedDataFrameFormat? = null,
228236
header: List<String> = emptyList(),
229237
formats: List<SupportedDataFrameFormat> = supportedFormats.filterIsInstance<SupportedDataFrameFormat>(),
230238
): ReadAnyFrame {
231-
if (format != null) return format to format.readDataFrame(file, header = header)
239+
if (format != null) return format to format.readDataFrame(path, header = header)
232240
formats.sortedBy { it.testOrder }.forEach {
233241
try {
234-
return it to it.readDataFrame(file, header = header)
242+
return it to it.readDataFrame(path, header = header)
235243
} catch (e: FileNotFoundException) {
236244
throw e
237245
} catch (e: Exception) {
@@ -249,16 +257,10 @@ internal data class GeneratedCode(val format: SupportedCodeGenerationFormat, val
249257
internal infix fun SupportedCodeGenerationFormat.to(code: Code) = GeneratedCode(this, code)
250258

251259
public fun DataFrame.Companion.read(file: File, header: List<String> = emptyList()): AnyFrame =
252-
read(
253-
file = file,
254-
format = guessFormat(file)?.also {
255-
if (it !is SupportedDataFrameFormat) error("Format $it does not support reading dataframes")
256-
} as SupportedDataFrameFormat?,
257-
header = header,
258-
).df
260+
read(file.toPath(), header)
259261

260262
public fun DataRow.Companion.read(file: File, header: List<String> = emptyList()): AnyRow =
261-
DataFrame.read(file, header).single()
263+
DataFrame.read(file.toPath(), header).single()
262264

263265
public fun DataFrame.Companion.read(url: URL, header: List<String> = emptyList()): AnyFrame =
264266
when {
@@ -293,3 +295,19 @@ public fun URL.readDataRow(header: List<String> = emptyList()): AnyRow = DataRow
293295
public fun File.readDataFrame(header: List<String> = emptyList()): AnyFrame = DataFrame.read(this, header)
294296

295297
public fun File.readDataRow(header: List<String> = emptyList()): AnyRow = DataRow.read(this, header)
298+
299+
public fun DataFrame.Companion.read(path: Path, header: List<String> = emptyList()): AnyFrame =
300+
read(
301+
path = path,
302+
format = guessFormat(path)?.also {
303+
if (it !is SupportedDataFrameFormat) error("Format $it does not support reading dataframes")
304+
} as SupportedDataFrameFormat?,
305+
header = header,
306+
).df
307+
308+
public fun DataRow.Companion.read(path: Path, header: List<String> = emptyList()): AnyRow =
309+
DataFrame.read(path, header).single()
310+
311+
public fun Path.readDataFrame(header: List<String> = emptyList()): AnyFrame = DataFrame.read(this, header)
312+
313+
public fun Path.readDataRow(header: List<String> = emptyList()): AnyRow = DataRow.read(this, header)

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/tsv.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import java.io.FileInputStream
1717
import java.io.InputStream
1818
import java.net.URL
1919
import java.nio.charset.Charset
20+
import java.nio.file.Path
2021

2122
@Deprecated(
2223
message = APACHE_CSV,
@@ -28,6 +29,10 @@ public class TSV : SupportedDataFrameFormat {
2829

2930
override fun readDataFrame(file: File, header: List<String>): AnyFrame = DataFrame.readTSV(file, header = header)
3031

32+
override fun readDataFrame(path: Path, header: List<String>): AnyFrame =
33+
// legacy TSV implementation lives in this module; delegate via File to keep behavior
34+
DataFrame.readTSV(path.toFile(), header = header)
35+
3136
override fun acceptsExtension(ext: String): Boolean = ext == "tsv"
3237

3338
override fun acceptsSample(sample: SupportedFormatSample): Boolean = true // Extension is enough

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/importDataSchema.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ import org.intellij.lang.annotations.Language
44
import java.io.File
55
import java.net.URI
66
import java.net.URL
7+
import java.nio.file.Path
78

89
public class ImportDataSchema(public val url: URL) {
910
public constructor(path: String) : this(URI(path).toURL())
11+
public constructor(path: Path) : this(path.toUri().toURL())
1012
public constructor(file: File) : this(file.toURI().toURL())
1113
}
1214

1315
public fun importDataSchema(url: URL): ImportDataSchema = ImportDataSchema(url)
1416

1517
public fun importDataSchema(path: String): ImportDataSchema = ImportDataSchema(path)
1618

19+
public fun importDataSchema(path: Path): ImportDataSchema = ImportDataSchema(path)
20+
1721
public fun importDataSchema(file: File): ImportDataSchema = ImportDataSchema(file)
1822

1923
@Language("kts")
@@ -50,6 +54,9 @@ internal val importDataSchema =
5054
/** Import the type-only data schema from [path]. */
5155
fun importDataSchema(path: String, name: String): Unit = importDataSchema(URI(path).toURL(), name)
5256
57+
/** Import the type-only data schema from [path]. */
58+
fun importDataSchema(path: Path, name: String): Unit = importDataSchema(path.toUri().toURL(), name)
59+
5360
/** Import the type-only data schema from [file]. */
5461
fun importDataSchema(file: File, name: String): Unit = importDataSchema(file.toURI().toURL(), name)
5562
""".trimIndent()

0 commit comments

Comments
 (0)