@@ -19,11 +19,21 @@ 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
27
37
import org.jetbrains.kotlinx.dataframe.values
28
38
import java.io.BufferedInputStream
29
39
import java.io.BufferedReader
@@ -46,6 +56,10 @@ import kotlin.reflect.KType
46
56
import kotlin.reflect.typeOf
47
57
import kotlin.time.Duration
48
58
59
+ @Deprecated(
60
+ message = APACHE_CSV ,
61
+ level = DeprecationLevel .WARNING ,
62
+ )
49
63
public class CSV (private val delimiter : Char = ' ,' ) : SupportedDataFrameFormat {
50
64
override fun readDataFrame (stream : InputStream , header : List <String >): AnyFrame =
51
65
DataFrame .readCSV(stream = stream, delimiter = delimiter, header = header)
@@ -57,14 +71,18 @@ public class CSV(private val delimiter: Char = ',') : SupportedDataFrameFormat {
57
71
58
72
override fun acceptsSample (sample : SupportedFormatSample ): Boolean = true // Extension is enough
59
73
60
- override val testOrder: Int = 20000
74
+ override val testOrder: Int = 20_000
61
75
62
76
override fun createDefaultReadMethod (pathRepresentation : String? ): DefaultReadDfMethod {
63
77
val arguments = MethodArguments ().add(" delimiter" , typeOf<Char >(), " '%L'" , delimiter)
64
78
return DefaultReadCsvMethod (pathRepresentation, arguments)
65
79
}
66
80
}
67
81
82
+ @Deprecated(
83
+ message = APACHE_CSV ,
84
+ level = DeprecationLevel .WARNING ,
85
+ )
68
86
public enum class CSVType (public val format : CSVFormat ) {
69
87
DEFAULT (
70
88
CSVFormat .DEFAULT .builder()
@@ -87,6 +105,10 @@ internal fun isCompressed(file: File) = listOf("gz", "zip").contains(file.extens
87
105
88
106
internal fun isCompressed (url : URL ) = isCompressed(url.path)
89
107
108
+ @Deprecated(
109
+ message = APACHE_CSV ,
110
+ level = DeprecationLevel .HIDDEN , // clashes with the new readDelim
111
+ )
90
112
@Refine
91
113
@Interpretable(" ReadDelimStr" )
92
114
public fun DataFrame.Companion.readDelimStr (
@@ -106,7 +128,7 @@ public fun DataFrame.Companion.readDelimStr(
106
128
107
129
@Deprecated(
108
130
message = DF_READ_NO_CSV ,
109
- replaceWith = ReplaceWith (DF_READ_NO_CSV_REPLACE ),
131
+ replaceWith = ReplaceWith (DF_READ_NO_CSV_REPLACE , READ_CSV_IMPORT ),
110
132
level = DeprecationLevel .ERROR ,
111
133
)
112
134
public fun DataFrame.Companion.read (
@@ -118,22 +140,13 @@ public fun DataFrame.Companion.read(
118
140
readLines : Int? = null,
119
141
duplicate : Boolean = true,
120
142
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
- }
143
+ ): DataFrame <* > = error(DF_READ_NO_CSV )
136
144
145
+ @Deprecated(
146
+ message = READ_CSV ,
147
+ replaceWith = ReplaceWith (READ_CSV_FILE_OR_URL_REPLACE , READ_CSV_IMPORT ),
148
+ level = DeprecationLevel .WARNING ,
149
+ )
137
150
@OptInRefine
138
151
@Interpretable(" ReadCSV0" )
139
152
public fun DataFrame.Companion.readCSV (
@@ -163,6 +176,11 @@ public fun DataFrame.Companion.readCSV(
163
176
)
164
177
}
165
178
179
+ @Deprecated(
180
+ message = READ_CSV ,
181
+ replaceWith = ReplaceWith (READ_CSV_FILE_REPLACE , READ_CSV_IMPORT ),
182
+ level = DeprecationLevel .WARNING ,
183
+ )
166
184
public fun DataFrame.Companion.readCSV (
167
185
file : File ,
168
186
delimiter : Char = ',',
@@ -188,6 +206,11 @@ public fun DataFrame.Companion.readCSV(
188
206
parserOptions,
189
207
)
190
208
209
+ @Deprecated(
210
+ message = READ_CSV ,
211
+ replaceWith = ReplaceWith (READ_CSV_URL_REPLACE , READ_CSV_IMPORT ),
212
+ level = DeprecationLevel .WARNING ,
213
+ )
191
214
public fun DataFrame.Companion.readCSV (
192
215
url : URL ,
193
216
delimiter : Char = ',',
@@ -212,6 +235,11 @@ public fun DataFrame.Companion.readCSV(
212
235
parserOptions,
213
236
)
214
237
238
+ @Deprecated(
239
+ message = READ_CSV ,
240
+ replaceWith = ReplaceWith (READ_CSV_STREAM_REPLACE , READ_CSV_IMPORT ),
241
+ level = DeprecationLevel .WARNING ,
242
+ )
215
243
public fun DataFrame.Companion.readCSV (
216
244
stream : InputStream ,
217
245
delimiter : Char = ',',
@@ -238,13 +266,6 @@ public fun DataFrame.Companion.readCSV(
238
266
parserOptions,
239
267
)
240
268
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
269
@Deprecated(
249
270
message = AS_URL ,
250
271
replaceWith = ReplaceWith (AS_URL_REPLACE , AS_URL_IMPORT ),
@@ -264,6 +285,11 @@ private fun getFormat(
264
285
.setAllowMissingColumnNames(duplicate)
265
286
.build()
266
287
288
+ @Deprecated(
289
+ message = READ_DELIM ,
290
+ replaceWith = ReplaceWith (READ_DELIM_STREAM_REPLACE ),
291
+ level = DeprecationLevel .WARNING ,
292
+ )
267
293
public fun DataFrame.Companion.readDelim (
268
294
inStream : InputStream ,
269
295
delimiter : Char = ',',
@@ -343,6 +369,11 @@ public fun ColType.toKType(): KType =
343
369
ColType .Char -> typeOf<Char >()
344
370
}
345
371
372
+ @Deprecated(
373
+ message = READ_DELIM ,
374
+ replaceWith = ReplaceWith (READ_DELIM_READER_REPLACE ),
375
+ level = DeprecationLevel .WARNING ,
376
+ )
346
377
public fun DataFrame.Companion.readDelim (
347
378
reader : Reader ,
348
379
format : CSVFormat = CSVFormat .DEFAULT .builder()
@@ -370,7 +401,7 @@ public fun DataFrame.Companion.readDelim(
370
401
" `DataFrame.readCSV()`." ,
371
402
)
372
403
}
373
-
404
+ // TODO deprecate
374
405
public fun AnyFrame.writeCSV (file : File , format : CSVFormat = CSVFormat .DEFAULT ): Unit =
375
406
writeCSV(FileWriter (file), format)
376
407
0 commit comments