@@ -19,18 +19,35 @@ import org.jetbrains.kotlinx.dataframe.codeGen.DefaultReadCsvMethod
19
19
import org.jetbrains.kotlinx.dataframe.codeGen.DefaultReadDfMethod
20
20
import org.jetbrains.kotlinx.dataframe.impl.api.parse
21
21
import org.jetbrains.kotlinx.dataframe.impl.io.readDelimImpl
22
+ import org.jetbrains.kotlinx.dataframe.util.APACHE_CSV
22
23
import org.jetbrains.kotlinx.dataframe.util.AS_URL
23
24
import org.jetbrains.kotlinx.dataframe.util.AS_URL_IMPORT
24
25
import org.jetbrains.kotlinx.dataframe.util.AS_URL_REPLACE
25
26
import org.jetbrains.kotlinx.dataframe.util.DF_READ_NO_CSV
26
27
import org.jetbrains.kotlinx.dataframe.util.DF_READ_NO_CSV_REPLACE
28
+ import org.jetbrains.kotlinx.dataframe.util.READ_CSV
29
+ import org.jetbrains.kotlinx.dataframe.util.READ_CSV_FILE_OR_URL_REPLACE
30
+ import org.jetbrains.kotlinx.dataframe.util.READ_CSV_FILE_REPLACE
31
+ import org.jetbrains.kotlinx.dataframe.util.READ_CSV_IMPORT
32
+ import org.jetbrains.kotlinx.dataframe.util.READ_CSV_STREAM_REPLACE
33
+ import org.jetbrains.kotlinx.dataframe.util.READ_CSV_URL_REPLACE
34
+ import org.jetbrains.kotlinx.dataframe.util.READ_DELIM
35
+ import org.jetbrains.kotlinx.dataframe.util.READ_DELIM_READER_REPLACE
36
+ import org.jetbrains.kotlinx.dataframe.util.READ_DELIM_STREAM_REPLACE
37
+ import org.jetbrains.kotlinx.dataframe.util.TO_CSV
38
+ import org.jetbrains.kotlinx.dataframe.util.TO_CSV_IMPORT
39
+ import org.jetbrains.kotlinx.dataframe.util.TO_CSV_REPLACE
40
+ import org.jetbrains.kotlinx.dataframe.util.WRITE_CSV
41
+ import org.jetbrains.kotlinx.dataframe.util.WRITE_CSV_FILE_REPLACE
42
+ import org.jetbrains.kotlinx.dataframe.util.WRITE_CSV_IMPORT
43
+ import org.jetbrains.kotlinx.dataframe.util.WRITE_CSV_PATH_REPLACE
44
+ import org.jetbrains.kotlinx.dataframe.util.WRITE_CSV_WRITER_REPLACE
27
45
import org.jetbrains.kotlinx.dataframe.values
28
46
import java.io.BufferedInputStream
29
47
import java.io.BufferedReader
30
48
import java.io.File
31
49
import java.io.FileInputStream
32
50
import java.io.FileWriter
33
- import java.io.IOException
34
51
import java.io.InputStream
35
52
import java.io.InputStreamReader
36
53
import java.io.Reader
@@ -46,6 +63,7 @@ import kotlin.reflect.KType
46
63
import kotlin.reflect.typeOf
47
64
import kotlin.time.Duration
48
65
66
+ @Deprecated(message = APACHE_CSV , level = DeprecationLevel .WARNING )
49
67
public class CSV (private val delimiter : Char = ' ,' ) : SupportedDataFrameFormat {
50
68
override fun readDataFrame (stream : InputStream , header : List <String >): AnyFrame =
51
69
DataFrame .readCSV(stream = stream, delimiter = delimiter, header = header)
@@ -57,14 +75,18 @@ public class CSV(private val delimiter: Char = ',') : SupportedDataFrameFormat {
57
75
58
76
override fun acceptsSample (sample : SupportedFormatSample ): Boolean = true // Extension is enough
59
77
60
- override val testOrder: Int = 20000
78
+ override val testOrder: Int = 20_001
61
79
62
80
override fun createDefaultReadMethod (pathRepresentation : String? ): DefaultReadDfMethod {
63
81
val arguments = MethodArguments ().add(" delimiter" , typeOf<Char >(), " '%L'" , delimiter)
64
82
return DefaultReadCsvMethod (pathRepresentation, arguments)
65
83
}
66
84
}
67
85
86
+ @Deprecated(
87
+ message = APACHE_CSV ,
88
+ level = DeprecationLevel .WARNING ,
89
+ )
68
90
public enum class CSVType (public val format : CSVFormat ) {
69
91
DEFAULT (
70
92
CSVFormat .DEFAULT .builder()
@@ -81,12 +103,19 @@ public enum class CSVType(public val format: CSVFormat) {
81
103
82
104
private val defaultCharset = Charsets .UTF_8
83
105
106
+ @Deprecated(" " , level = DeprecationLevel .WARNING )
84
107
internal fun isCompressed (fileOrUrl : String ) = listOf (" gz" , " zip" ).contains(fileOrUrl.split(" ." ).last())
85
108
109
+ @Deprecated(" " , level = DeprecationLevel .WARNING )
86
110
internal fun isCompressed (file : File ) = listOf (" gz" , " zip" ).contains(file.extension)
87
111
112
+ @Deprecated(" " , level = DeprecationLevel .WARNING )
88
113
internal fun isCompressed (url : URL ) = isCompressed(url.path)
89
114
115
+ @Deprecated(
116
+ message = APACHE_CSV ,
117
+ level = DeprecationLevel .HIDDEN , // clashes with the new readDelim
118
+ )
90
119
@Refine
91
120
@Interpretable(" ReadDelimStr" )
92
121
public fun DataFrame.Companion.readDelimStr (
@@ -106,7 +135,7 @@ public fun DataFrame.Companion.readDelimStr(
106
135
107
136
@Deprecated(
108
137
message = DF_READ_NO_CSV ,
109
- replaceWith = ReplaceWith (DF_READ_NO_CSV_REPLACE ),
138
+ replaceWith = ReplaceWith (DF_READ_NO_CSV_REPLACE , READ_CSV_IMPORT ),
110
139
level = DeprecationLevel .ERROR ,
111
140
)
112
141
public fun DataFrame.Companion.read (
@@ -118,22 +147,13 @@ public fun DataFrame.Companion.read(
118
147
readLines : Int? = null,
119
148
duplicate : Boolean = true,
120
149
charset : Charset = Charsets .UTF_8 ,
121
- ): DataFrame <* > =
122
- catchHttpResponse(asUrl(fileOrUrl)) {
123
- readDelim(
124
- it,
125
- delimiter,
126
- header,
127
- isCompressed(fileOrUrl),
128
- getCSVType(fileOrUrl),
129
- colTypes,
130
- skipLines,
131
- readLines,
132
- duplicate,
133
- charset,
134
- )
135
- }
150
+ ): DataFrame <* > = error(DF_READ_NO_CSV )
136
151
152
+ @Deprecated(
153
+ message = READ_CSV ,
154
+ replaceWith = ReplaceWith (READ_CSV_FILE_OR_URL_REPLACE , READ_CSV_IMPORT ),
155
+ level = DeprecationLevel .WARNING ,
156
+ )
137
157
@OptInRefine
138
158
@Interpretable(" ReadCSV0" )
139
159
public fun DataFrame.Companion.readCSV (
@@ -163,6 +183,11 @@ public fun DataFrame.Companion.readCSV(
163
183
)
164
184
}
165
185
186
+ @Deprecated(
187
+ message = READ_CSV ,
188
+ replaceWith = ReplaceWith (READ_CSV_FILE_REPLACE , READ_CSV_IMPORT ),
189
+ level = DeprecationLevel .WARNING ,
190
+ )
166
191
public fun DataFrame.Companion.readCSV (
167
192
file : File ,
168
193
delimiter : Char = ',',
@@ -188,6 +213,11 @@ public fun DataFrame.Companion.readCSV(
188
213
parserOptions,
189
214
)
190
215
216
+ @Deprecated(
217
+ message = READ_CSV ,
218
+ replaceWith = ReplaceWith (READ_CSV_URL_REPLACE , READ_CSV_IMPORT ),
219
+ level = DeprecationLevel .WARNING ,
220
+ )
191
221
public fun DataFrame.Companion.readCSV (
192
222
url : URL ,
193
223
delimiter : Char = ',',
@@ -212,6 +242,11 @@ public fun DataFrame.Companion.readCSV(
212
242
parserOptions,
213
243
)
214
244
245
+ @Deprecated(
246
+ message = READ_CSV ,
247
+ replaceWith = ReplaceWith (READ_CSV_STREAM_REPLACE , READ_CSV_IMPORT ),
248
+ level = DeprecationLevel .WARNING ,
249
+ )
215
250
public fun DataFrame.Companion.readCSV (
216
251
stream : InputStream ,
217
252
delimiter : Char = ',',
@@ -238,13 +273,6 @@ public fun DataFrame.Companion.readCSV(
238
273
parserOptions,
239
274
)
240
275
241
- private fun getCSVType (path : String ): CSVType =
242
- when (path.substringAfterLast(' .' ).lowercase()) {
243
- " csv" -> CSVType .DEFAULT
244
- " tdf" -> CSVType .TDF
245
- else -> throw IOException (" Unknown file format" )
246
- }
247
-
248
276
@Deprecated(
249
277
message = AS_URL ,
250
278
replaceWith = ReplaceWith (AS_URL_REPLACE , AS_URL_IMPORT ),
@@ -264,6 +292,11 @@ private fun getFormat(
264
292
.setAllowMissingColumnNames(duplicate)
265
293
.build()
266
294
295
+ @Deprecated(
296
+ message = READ_DELIM ,
297
+ replaceWith = ReplaceWith (READ_DELIM_STREAM_REPLACE ),
298
+ level = DeprecationLevel .WARNING ,
299
+ )
267
300
public fun DataFrame.Companion.readDelim (
268
301
inStream : InputStream ,
269
302
delimiter : Char = ',',
@@ -343,6 +376,11 @@ public fun ColType.toKType(): KType =
343
376
ColType .Char -> typeOf<Char >()
344
377
}
345
378
379
+ @Deprecated(
380
+ message = READ_DELIM ,
381
+ replaceWith = ReplaceWith (READ_DELIM_READER_REPLACE ),
382
+ level = DeprecationLevel .WARNING ,
383
+ )
346
384
public fun DataFrame.Companion.readDelim (
347
385
reader : Reader ,
348
386
format : CSVFormat = CSVFormat .DEFAULT .builder()
@@ -371,12 +409,27 @@ public fun DataFrame.Companion.readDelim(
371
409
)
372
410
}
373
411
412
+ @Deprecated(
413
+ message = WRITE_CSV ,
414
+ replaceWith = ReplaceWith (WRITE_CSV_FILE_REPLACE , WRITE_CSV_IMPORT ),
415
+ level = DeprecationLevel .WARNING ,
416
+ )
374
417
public fun AnyFrame.writeCSV (file : File , format : CSVFormat = CSVFormat .DEFAULT ): Unit =
375
418
writeCSV(FileWriter (file), format)
376
419
420
+ @Deprecated(
421
+ message = WRITE_CSV ,
422
+ replaceWith = ReplaceWith (WRITE_CSV_PATH_REPLACE , WRITE_CSV_IMPORT ),
423
+ level = DeprecationLevel .WARNING ,
424
+ )
377
425
public fun AnyFrame.writeCSV (path : String , format : CSVFormat = CSVFormat .DEFAULT ): Unit =
378
426
writeCSV(FileWriter (path), format)
379
427
428
+ @Deprecated(
429
+ message = WRITE_CSV ,
430
+ replaceWith = ReplaceWith (WRITE_CSV_WRITER_REPLACE , WRITE_CSV_IMPORT ),
431
+ level = DeprecationLevel .WARNING ,
432
+ )
380
433
public fun AnyFrame.writeCSV (writer : Appendable , format : CSVFormat = CSVFormat .DEFAULT ) {
381
434
format.print (writer).use { printer ->
382
435
if (! format.skipHeaderRecord) {
@@ -395,6 +448,11 @@ public fun AnyFrame.writeCSV(writer: Appendable, format: CSVFormat = CSVFormat.D
395
448
}
396
449
}
397
450
451
+ @Deprecated(
452
+ message = TO_CSV ,
453
+ replaceWith = ReplaceWith (TO_CSV_REPLACE , TO_CSV_IMPORT ),
454
+ level = DeprecationLevel .WARNING ,
455
+ )
398
456
public fun AnyFrame.toCsv (format : CSVFormat = CSVFormat .DEFAULT ): String =
399
457
StringWriter ().use {
400
458
this .writeCSV(it, format)
0 commit comments