@@ -19,11 +19,21 @@ import org.jetbrains.kotlinx.dataframe.codeGen.DefaultReadCsvMethod
1919import org.jetbrains.kotlinx.dataframe.codeGen.DefaultReadDfMethod
2020import org.jetbrains.kotlinx.dataframe.impl.api.parse
2121import org.jetbrains.kotlinx.dataframe.impl.io.readDelimImpl
22+ import org.jetbrains.kotlinx.dataframe.util.APACHE_CSV
2223import org.jetbrains.kotlinx.dataframe.util.AS_URL
2324import org.jetbrains.kotlinx.dataframe.util.AS_URL_IMPORT
2425import org.jetbrains.kotlinx.dataframe.util.AS_URL_REPLACE
2526import org.jetbrains.kotlinx.dataframe.util.DF_READ_NO_CSV
2627import 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
2737import org.jetbrains.kotlinx.dataframe.values
2838import java.io.BufferedInputStream
2939import java.io.BufferedReader
@@ -46,6 +56,10 @@ import kotlin.reflect.KType
4656import kotlin.reflect.typeOf
4757import kotlin.time.Duration
4858
59+ @Deprecated(
60+ message = APACHE_CSV ,
61+ level = DeprecationLevel .WARNING ,
62+ )
4963public class CSV (private val delimiter : Char = ' ,' ) : SupportedDataFrameFormat {
5064 override fun readDataFrame (stream : InputStream , header : List <String >): AnyFrame =
5165 DataFrame .readCSV(stream = stream, delimiter = delimiter, header = header)
@@ -57,14 +71,18 @@ public class CSV(private val delimiter: Char = ',') : SupportedDataFrameFormat {
5771
5872 override fun acceptsSample (sample : SupportedFormatSample ): Boolean = true // Extension is enough
5973
60- override val testOrder: Int = 20000
74+ override val testOrder: Int = 20_000
6175
6276 override fun createDefaultReadMethod (pathRepresentation : String? ): DefaultReadDfMethod {
6377 val arguments = MethodArguments ().add(" delimiter" , typeOf<Char >(), " '%L'" , delimiter)
6478 return DefaultReadCsvMethod (pathRepresentation, arguments)
6579 }
6680}
6781
82+ @Deprecated(
83+ message = APACHE_CSV ,
84+ level = DeprecationLevel .WARNING ,
85+ )
6886public enum class CSVType (public val format : CSVFormat ) {
6987 DEFAULT (
7088 CSVFormat .DEFAULT .builder()
@@ -87,6 +105,10 @@ internal fun isCompressed(file: File) = listOf("gz", "zip").contains(file.extens
87105
88106internal fun isCompressed (url : URL ) = isCompressed(url.path)
89107
108+ @Deprecated(
109+ message = APACHE_CSV ,
110+ level = DeprecationLevel .HIDDEN , // clashes with the new readDelim
111+ )
90112@Refine
91113@Interpretable(" ReadDelimStr" )
92114public fun DataFrame.Companion.readDelimStr (
@@ -106,7 +128,7 @@ public fun DataFrame.Companion.readDelimStr(
106128
107129@Deprecated(
108130 message = DF_READ_NO_CSV ,
109- replaceWith = ReplaceWith (DF_READ_NO_CSV_REPLACE ),
131+ replaceWith = ReplaceWith (DF_READ_NO_CSV_REPLACE , READ_CSV_IMPORT ),
110132 level = DeprecationLevel .ERROR ,
111133)
112134public fun DataFrame.Companion.read (
@@ -118,22 +140,13 @@ public fun DataFrame.Companion.read(
118140 readLines : Int? = null,
119141 duplicate : Boolean = true,
120142 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 )
136144
145+ @Deprecated(
146+ message = READ_CSV ,
147+ replaceWith = ReplaceWith (READ_CSV_FILE_OR_URL_REPLACE , READ_CSV_IMPORT ),
148+ level = DeprecationLevel .WARNING ,
149+ )
137150@OptInRefine
138151@Interpretable(" ReadCSV0" )
139152public fun DataFrame.Companion.readCSV (
@@ -163,6 +176,11 @@ public fun DataFrame.Companion.readCSV(
163176 )
164177 }
165178
179+ @Deprecated(
180+ message = READ_CSV ,
181+ replaceWith = ReplaceWith (READ_CSV_FILE_REPLACE , READ_CSV_IMPORT ),
182+ level = DeprecationLevel .WARNING ,
183+ )
166184public fun DataFrame.Companion.readCSV (
167185 file : File ,
168186 delimiter : Char = ',',
@@ -188,6 +206,11 @@ public fun DataFrame.Companion.readCSV(
188206 parserOptions,
189207 )
190208
209+ @Deprecated(
210+ message = READ_CSV ,
211+ replaceWith = ReplaceWith (READ_CSV_URL_REPLACE , READ_CSV_IMPORT ),
212+ level = DeprecationLevel .WARNING ,
213+ )
191214public fun DataFrame.Companion.readCSV (
192215 url : URL ,
193216 delimiter : Char = ',',
@@ -212,6 +235,11 @@ public fun DataFrame.Companion.readCSV(
212235 parserOptions,
213236 )
214237
238+ @Deprecated(
239+ message = READ_CSV ,
240+ replaceWith = ReplaceWith (READ_CSV_STREAM_REPLACE , READ_CSV_IMPORT ),
241+ level = DeprecationLevel .WARNING ,
242+ )
215243public fun DataFrame.Companion.readCSV (
216244 stream : InputStream ,
217245 delimiter : Char = ',',
@@ -238,13 +266,6 @@ public fun DataFrame.Companion.readCSV(
238266 parserOptions,
239267 )
240268
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-
248269@Deprecated(
249270 message = AS_URL ,
250271 replaceWith = ReplaceWith (AS_URL_REPLACE , AS_URL_IMPORT ),
@@ -264,6 +285,11 @@ private fun getFormat(
264285 .setAllowMissingColumnNames(duplicate)
265286 .build()
266287
288+ @Deprecated(
289+ message = READ_DELIM ,
290+ replaceWith = ReplaceWith (READ_DELIM_STREAM_REPLACE ),
291+ level = DeprecationLevel .WARNING ,
292+ )
267293public fun DataFrame.Companion.readDelim (
268294 inStream : InputStream ,
269295 delimiter : Char = ',',
@@ -343,6 +369,11 @@ public fun ColType.toKType(): KType =
343369 ColType .Char -> typeOf<Char >()
344370 }
345371
372+ @Deprecated(
373+ message = READ_DELIM ,
374+ replaceWith = ReplaceWith (READ_DELIM_READER_REPLACE ),
375+ level = DeprecationLevel .WARNING ,
376+ )
346377public fun DataFrame.Companion.readDelim (
347378 reader : Reader ,
348379 format : CSVFormat = CSVFormat .DEFAULT .builder()
@@ -370,7 +401,7 @@ public fun DataFrame.Companion.readDelim(
370401 " `DataFrame.readCSV()`." ,
371402 )
372403 }
373-
404+ // TODO deprecate
374405public fun AnyFrame.writeCSV (file : File , format : CSVFormat = CSVFormat .DEFAULT ): Unit =
375406 writeCSV(FileWriter (file), format)
376407
0 commit comments