diff --git a/core/api/core.api b/core/api/core.api index b585b69cc4..32d5d83e53 100644 --- a/core/api/core.api +++ b/core/api/core.api @@ -1535,6 +1535,8 @@ public final class org/jetbrains/kotlinx/dataframe/api/ConvertKt { public static final fun convertToStringFromT (Lorg/jetbrains/kotlinx/dataframe/DataColumn;)Lorg/jetbrains/kotlinx/dataframe/DataColumn; public static final fun convertToURL (Lorg/jetbrains/kotlinx/dataframe/DataColumn;)Lorg/jetbrains/kotlinx/dataframe/DataColumn; public static final fun convertToURLFromStringNullable (Lorg/jetbrains/kotlinx/dataframe/DataColumn;)Lorg/jetbrains/kotlinx/dataframe/DataColumn; + public static final fun convertToUrl (Lorg/jetbrains/kotlinx/dataframe/DataColumn;)Lorg/jetbrains/kotlinx/dataframe/DataColumn; + public static final fun convertToUrlFromStringNullable (Lorg/jetbrains/kotlinx/dataframe/DataColumn;)Lorg/jetbrains/kotlinx/dataframe/DataColumn; public static final fun to (Lorg/jetbrains/kotlinx/dataframe/api/Convert;Lkotlin/jvm/functions/Function2;)Lorg/jetbrains/kotlinx/dataframe/DataFrame; public static final fun to (Lorg/jetbrains/kotlinx/dataframe/api/Convert;Lkotlin/reflect/KType;)Lorg/jetbrains/kotlinx/dataframe/DataFrame; public static final fun toBigDecimal (Lorg/jetbrains/kotlinx/dataframe/api/Convert;)Lorg/jetbrains/kotlinx/dataframe/DataFrame; @@ -1610,6 +1612,8 @@ public final class org/jetbrains/kotlinx/dataframe/api/ConvertKt { public static final fun toLongTAny (Lorg/jetbrains/kotlinx/dataframe/api/Convert;)Lorg/jetbrains/kotlinx/dataframe/DataFrame; public static final fun toStr (Lorg/jetbrains/kotlinx/dataframe/api/Convert;)Lorg/jetbrains/kotlinx/dataframe/DataFrame; public static final fun toStrTAny (Lorg/jetbrains/kotlinx/dataframe/api/Convert;)Lorg/jetbrains/kotlinx/dataframe/DataFrame; + public static final fun toURLFromString (Lorg/jetbrains/kotlinx/dataframe/api/Convert;)Lorg/jetbrains/kotlinx/dataframe/DataFrame; + public static final fun toURLFromStringNullable (Lorg/jetbrains/kotlinx/dataframe/api/Convert;)Lorg/jetbrains/kotlinx/dataframe/DataFrame; public static final fun toUrlFromString (Lorg/jetbrains/kotlinx/dataframe/api/Convert;)Lorg/jetbrains/kotlinx/dataframe/DataFrame; public static final fun toUrlFromStringNullable (Lorg/jetbrains/kotlinx/dataframe/api/Convert;)Lorg/jetbrains/kotlinx/dataframe/DataFrame; } @@ -2221,10 +2225,10 @@ public final class org/jetbrains/kotlinx/dataframe/api/FormattedFrame { public fun (Lorg/jetbrains/kotlinx/dataframe/DataFrame;Lkotlin/jvm/functions/Function3;)V public synthetic fun (Lorg/jetbrains/kotlinx/dataframe/DataFrame;Lkotlin/jvm/functions/Function3;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun getDisplayConfiguration (Lorg/jetbrains/kotlinx/dataframe/io/DisplayConfiguration;)Lorg/jetbrains/kotlinx/dataframe/io/DisplayConfiguration; - public final fun toHTML (Lorg/jetbrains/kotlinx/dataframe/io/DisplayConfiguration;)Lorg/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData; - public static synthetic fun toHTML$default (Lorg/jetbrains/kotlinx/dataframe/api/FormattedFrame;Lorg/jetbrains/kotlinx/dataframe/io/DisplayConfiguration;ILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData; - public final fun toStandaloneHTML (Lorg/jetbrains/kotlinx/dataframe/io/DisplayConfiguration;)Lorg/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData; - public static synthetic fun toStandaloneHTML$default (Lorg/jetbrains/kotlinx/dataframe/api/FormattedFrame;Lorg/jetbrains/kotlinx/dataframe/io/DisplayConfiguration;ILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData; + public final fun toHtml (Lorg/jetbrains/kotlinx/dataframe/io/DisplayConfiguration;)Lorg/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData; + public static synthetic fun toHtml$default (Lorg/jetbrains/kotlinx/dataframe/api/FormattedFrame;Lorg/jetbrains/kotlinx/dataframe/io/DisplayConfiguration;ILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData; + public final fun toStandaloneHtml (Lorg/jetbrains/kotlinx/dataframe/io/DisplayConfiguration;)Lorg/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData; + public static synthetic fun toStandaloneHtml$default (Lorg/jetbrains/kotlinx/dataframe/api/FormattedFrame;Lorg/jetbrains/kotlinx/dataframe/io/DisplayConfiguration;ILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData; } public final class org/jetbrains/kotlinx/dataframe/api/FormattingDSL { @@ -6087,6 +6091,9 @@ public final class org/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData { public final fun writeHTML (Ljava/io/File;)V public final fun writeHTML (Ljava/lang/String;)V public final fun writeHTML (Ljava/nio/file/Path;)V + public final fun writeHtml (Ljava/io/File;)V + public final fun writeHtml (Ljava/lang/String;)V + public final fun writeHtml (Ljava/nio/file/Path;)V } public final class org/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData$Companion { @@ -6163,8 +6170,12 @@ public final class org/jetbrains/kotlinx/dataframe/io/GuessKt { public final class org/jetbrains/kotlinx/dataframe/io/HtmlKt { public static final fun toHTML (Lorg/jetbrains/kotlinx/dataframe/DataFrame;Lorg/jetbrains/kotlinx/dataframe/io/DisplayConfiguration;Lorg/jetbrains/kotlinx/dataframe/jupyter/CellRenderer;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData; public static synthetic fun toHTML$default (Lorg/jetbrains/kotlinx/dataframe/DataFrame;Lorg/jetbrains/kotlinx/dataframe/io/DisplayConfiguration;Lorg/jetbrains/kotlinx/dataframe/jupyter/CellRenderer;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData; + public static final fun toHtml (Lorg/jetbrains/kotlinx/dataframe/DataFrame;Lorg/jetbrains/kotlinx/dataframe/io/DisplayConfiguration;Lorg/jetbrains/kotlinx/dataframe/jupyter/CellRenderer;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData; + public static synthetic fun toHtml$default (Lorg/jetbrains/kotlinx/dataframe/DataFrame;Lorg/jetbrains/kotlinx/dataframe/io/DisplayConfiguration;Lorg/jetbrains/kotlinx/dataframe/jupyter/CellRenderer;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData; public static final fun toStandaloneHTML (Lorg/jetbrains/kotlinx/dataframe/DataFrame;Lorg/jetbrains/kotlinx/dataframe/io/DisplayConfiguration;Lorg/jetbrains/kotlinx/dataframe/jupyter/CellRenderer;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData; public static synthetic fun toStandaloneHTML$default (Lorg/jetbrains/kotlinx/dataframe/DataFrame;Lorg/jetbrains/kotlinx/dataframe/io/DisplayConfiguration;Lorg/jetbrains/kotlinx/dataframe/jupyter/CellRenderer;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData; + public static final fun toStandaloneHtml (Lorg/jetbrains/kotlinx/dataframe/DataFrame;Lorg/jetbrains/kotlinx/dataframe/io/DisplayConfiguration;Lorg/jetbrains/kotlinx/dataframe/jupyter/CellRenderer;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData; + public static synthetic fun toStandaloneHtml$default (Lorg/jetbrains/kotlinx/dataframe/DataFrame;Lorg/jetbrains/kotlinx/dataframe/io/DisplayConfiguration;Lorg/jetbrains/kotlinx/dataframe/jupyter/CellRenderer;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData; public static final fun toStaticHtml (Lorg/jetbrains/kotlinx/dataframe/DataFrame;Lorg/jetbrains/kotlinx/dataframe/io/DisplayConfiguration;Lorg/jetbrains/kotlinx/dataframe/jupyter/CellRenderer;ZZ)Lorg/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData; public static synthetic fun toStaticHtml$default (Lorg/jetbrains/kotlinx/dataframe/DataFrame;Lorg/jetbrains/kotlinx/dataframe/io/DisplayConfiguration;Lorg/jetbrains/kotlinx/dataframe/jupyter/CellRenderer;ZZILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData; } diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/convert.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/convert.kt index fe450c1dcb..85c0edb5b6 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/convert.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/convert.kt @@ -50,8 +50,13 @@ import org.jetbrains.kotlinx.dataframe.impl.io.FastDoubleParser import org.jetbrains.kotlinx.dataframe.io.toDataFrame import org.jetbrains.kotlinx.dataframe.util.CONVERT_TO import org.jetbrains.kotlinx.dataframe.util.CONVERT_TO_REPLACE +import org.jetbrains.kotlinx.dataframe.util.CONVERT_TO_URL +import org.jetbrains.kotlinx.dataframe.util.CONVERT_TO_URL_REPLACE +import org.jetbrains.kotlinx.dataframe.util.TO_URL +import org.jetbrains.kotlinx.dataframe.util.TO_URL_REPLACE import java.math.BigDecimal import java.math.BigInteger +import java.net.URI import java.net.URL import java.util.Locale import kotlin.reflect.KProperty @@ -180,7 +185,7 @@ internal interface ConvertDocs { * `| `__`.`__[**`toInstant`**][Convert.toInstant]`()` * * {@include [Indent]} - * `| `__`.`__[**`toURL`**][Convert.toURL]`()` + * `| `__`.`__[**`toUrl`**][Convert.toUrl]`()` * * {@include [Indent]} * `| `__`.`__[**`toIFrame`**][Convert.toIFrame]`()` @@ -325,7 +330,7 @@ public inline fun Convert.notNull( * - [toStr], [toInt], [toLong], [toDouble], [toFloat], [toBigDecimal], * [toBigInteger], [toBoolean] – convert to standard types. * - [toLocalDateTime], [toLocalDate], [toLocalTime], [toInstant] – convert to kotlinx.datetime types. - * - [toURL], [toIFrame], [toImg] – convert to special types. + * - [toUrl], [toIFrame], [toImg] – convert to special types. * - [toDataFrames] – converts a column of lists into separate DataFrames. * * See [Grammar][ConvertDocs.Grammar] for more details. @@ -956,20 +961,34 @@ public fun Convert.toImg(width: Int? = null, height: Int? // region toURL +@Deprecated(CONVERT_TO_URL, ReplaceWith(CONVERT_TO_URL_REPLACE), DeprecationLevel.ERROR) +public fun DataColumn.convertToURL(): DataColumn = convertToUrl() + /** * Converts values in this [String] column to an [URL]. * * @return A new [DataColumn] with an [URL] values. */ -public fun DataColumn.convertToURL(): DataColumn = map { URL(it) } +public fun DataColumn.convertToUrl(): DataColumn = map { URI(it).toURL() } + +@Deprecated(CONVERT_TO_URL, ReplaceWith(CONVERT_TO_URL_REPLACE), DeprecationLevel.ERROR) +@JvmName("convertToURLFromStringNullable") +public fun DataColumn.convertToURL(): DataColumn = convertToUrl() /** * Converts values in this [String] column to an [URL]. Preserves null values. * * @return A new [DataColumn] with an [URL] nullable values. */ -@JvmName("convertToURLFromStringNullable") -public fun DataColumn.convertToURL(): DataColumn = map { it?.let { URL(it) } } +@JvmName("convertToUrlFromStringNullable") +public fun DataColumn.convertToUrl(): DataColumn = map { it?.let { URI(it).toURL() } } + +@Deprecated(TO_URL, ReplaceWith(TO_URL_REPLACE), DeprecationLevel.ERROR) +@JvmName("toURLFromStringNullable") +@Refine +@Converter(URL::class, nullable = true) +@Interpretable("ToSpecificType") +public fun Convert.toURL(): DataFrame = asColumn { it.convertToUrl() } /** * Converts values in the [String] columns previously selected with [convert] to an [URL], @@ -980,7 +999,7 @@ public fun DataColumn.convertToURL(): DataColumn = map { it?.let * * ### Examples: * ```kotlin - * df.convert { webAddress }.toURL() + * df.convert { webAddress }.toUrl() * ``` * * @return A new [DataFrame] with the values converted to an [URL]. @@ -989,7 +1008,14 @@ public fun DataColumn.convertToURL(): DataColumn = map { it?.let @Refine @Converter(URL::class, nullable = true) @Interpretable("ToSpecificType") -public fun Convert.toURL(): DataFrame = asColumn { it.convertToURL() } +public fun Convert.toUrl(): DataFrame = asColumn { it.convertToUrl() } + +@Deprecated(TO_URL, ReplaceWith(TO_URL_REPLACE), DeprecationLevel.ERROR) +@JvmName("toURLFromString") +@Refine +@Converter(URL::class, nullable = false) +@Interpretable("ToSpecificType") +public fun Convert.toURL(): DataFrame = toUrl() /** * Converts values in the [String] columns previously selected with [convert] to an [URL], @@ -999,7 +1025,7 @@ public fun Convert.toURL(): DataFrame = asColumn { it.convert * * ### Examples: * ```kotlin - * df.convert { webAddress }.toURL() + * df.convert { webAddress }.toUrl() * ``` * * @return A new [DataFrame] with the values converted to an [URL]. @@ -1008,7 +1034,7 @@ public fun Convert.toURL(): DataFrame = asColumn { it.convert @Refine @Converter(URL::class, nullable = false) @Interpretable("ToSpecificType") -public fun Convert.toURL(): DataFrame = asColumn { it.convertToURL() } +public fun Convert.toUrl(): DataFrame = asColumn { it.convertToUrl() } // endregion diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/format.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/format.kt index fa9861ca14..8bdf1b1997 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/format.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/format.kt @@ -15,8 +15,8 @@ import org.jetbrains.kotlinx.dataframe.impl.api.formatImpl import org.jetbrains.kotlinx.dataframe.impl.api.linearGradient import org.jetbrains.kotlinx.dataframe.io.DataFrameHtmlData import org.jetbrains.kotlinx.dataframe.io.DisplayConfiguration -import org.jetbrains.kotlinx.dataframe.io.toHTML -import org.jetbrains.kotlinx.dataframe.io.toStandaloneHTML +import org.jetbrains.kotlinx.dataframe.io.toHtml +import org.jetbrains.kotlinx.dataframe.io.toStandaloneHtml import kotlin.reflect.KProperty // region DataFrame @@ -126,14 +126,14 @@ public class FormattedFrame(internal val df: DataFrame, internal val forma /** * @return DataFrameHtmlData without additional definitions. Can be rendered in Jupyter kernel environments */ - public fun toHTML(configuration: DisplayConfiguration = DisplayConfiguration.DEFAULT): DataFrameHtmlData = - df.toHTML(getDisplayConfiguration(configuration)) + public fun toHtml(configuration: DisplayConfiguration = DisplayConfiguration.DEFAULT): DataFrameHtmlData = + df.toHtml(getDisplayConfiguration(configuration)) /** * @return DataFrameHtmlData with table script and css definitions. Can be saved as an *.html file and displayed in the browser */ - public fun toStandaloneHTML(configuration: DisplayConfiguration = DisplayConfiguration.DEFAULT): DataFrameHtmlData = - df.toStandaloneHTML(getDisplayConfiguration(configuration)) + public fun toStandaloneHtml(configuration: DisplayConfiguration = DisplayConfiguration.DEFAULT): DataFrameHtmlData = + df.toStandaloneHtml(getDisplayConfiguration(configuration)) public fun getDisplayConfiguration(configuration: DisplayConfiguration): DisplayConfiguration = configuration.copy(cellFormatter = formatter as RowColFormatter<*, *>?) diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/parse.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/parse.kt index 5a3aa7d7c3..e0a19d9eff 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/parse.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/parse.kt @@ -41,6 +41,7 @@ import org.jetbrains.kotlinx.dataframe.io.isUrl import org.jetbrains.kotlinx.dataframe.values import java.math.BigDecimal import java.math.BigInteger +import java.net.URI import java.net.URL import java.text.ParsePosition import java.time.format.DateTimeFormatter @@ -240,7 +241,7 @@ internal object Parsers : GlobalParserOptions { toJavaLocalDateTimeOrNull(formatter) // since we accept a Java DateTimeFormatter ?.toKotlinLocalDateTime() - private fun String.toUrlOrNull(): URL? = if (isUrl(this)) catchSilent { URL(this) } else null + private fun String.toUrlOrNull(): URL? = if (isUrl(this)) catchSilent { URI(this).toURL() } else null private fun String.toBooleanOrNull() = when (uppercase(Locale.getDefault())) { diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/common.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/common.kt index b8afe09cd2..25a5d8a1ac 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/common.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/common.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlinx.dataframe.util.IS_URL_REPLACE import java.io.File import java.io.InputStream import java.net.HttpURLConnection +import java.net.URI import java.net.URL /** @@ -110,7 +111,7 @@ public fun isProtocolSupported(url: URL): Boolean = url.protocol in setOf("http" */ public fun asUrl(fileOrUrl: String): URL = if (isUrl(fileOrUrl)) { - URL(fileOrUrl).toURI() + URI(fileOrUrl) } else { File(fileOrUrl).also { require(it.exists()) { "File not found: \"$fileOrUrl\"" } diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt index 12c3e48e84..44b4520c2c 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt @@ -34,6 +34,12 @@ import org.jetbrains.kotlinx.dataframe.jupyter.RenderedContent import org.jetbrains.kotlinx.dataframe.name import org.jetbrains.kotlinx.dataframe.nrow import org.jetbrains.kotlinx.dataframe.size +import org.jetbrains.kotlinx.dataframe.util.TO_HTML +import org.jetbrains.kotlinx.dataframe.util.TO_HTML_REPLACE +import org.jetbrains.kotlinx.dataframe.util.TO_STANDALONE_HTML +import org.jetbrains.kotlinx.dataframe.util.TO_STANDALONE_HTML_REPLACE +import org.jetbrains.kotlinx.dataframe.util.WRITE_HTML +import org.jetbrains.kotlinx.dataframe.util.WRITE_HTML_REPLACE import java.awt.Desktop import java.awt.image.BufferedImage import java.io.File @@ -515,6 +521,20 @@ private fun AnyFrame.getColumnsHeaderGrid(): List DataFrame.toHTML( + configuration: DisplayConfiguration = DisplayConfiguration.DEFAULT, + cellRenderer: CellRenderer = DefaultCellRenderer, + getFooter: (DataFrame) -> String? = { "DataFrame [${it.size}]" }, +) = toHtml(configuration, cellRenderer, getFooter) + +@Deprecated(TO_STANDALONE_HTML, ReplaceWith(TO_STANDALONE_HTML_REPLACE), DeprecationLevel.ERROR) +public fun DataFrame.toStandaloneHTML( + configuration: DisplayConfiguration = DisplayConfiguration.DEFAULT, + cellRenderer: CellRenderer = DefaultCellRenderer, + getFooter: (DataFrame) -> String? = { "DataFrame [${it.size}]" }, +): DataFrameHtmlData = toStandaloneHtml(configuration, cellRenderer, getFooter) + /** * By default, cell content is formatted as text * Use [RenderedContent.media] or [IMG], [IFRAME] if you need custom HTML inside a cell. @@ -524,18 +544,18 @@ internal fun DataFrameHtmlData.print() = println(this) * the ["Open in browser"](https://www.jetbrains.com/help/idea/editing-html-files.html#ws_html_preview_output_procedure) feature of IntelliJ IDEA will automatically reload the file content when it's updated * @return DataFrameHtmlData with table script and css definitions */ -public fun DataFrame.toStandaloneHTML( +public fun DataFrame.toStandaloneHtml( configuration: DisplayConfiguration = DisplayConfiguration.DEFAULT, cellRenderer: CellRenderer = DefaultCellRenderer, getFooter: (DataFrame) -> String? = { "DataFrame [${it.size}]" }, -): DataFrameHtmlData = toHTML(configuration, cellRenderer, getFooter).withTableDefinitions() +): DataFrameHtmlData = toHtml(configuration, cellRenderer, getFooter).withTableDefinitions() /** * By default, cell content is formatted as text * Use [RenderedContent.media] or [IMG], [IFRAME] if you need custom HTML inside a cell. * @return DataFrameHtmlData without additional definitions. Can be rendered in Jupyter kernel environments */ -public fun DataFrame.toHTML( +public fun DataFrame.toHtml( configuration: DisplayConfiguration = DisplayConfiguration.DEFAULT, cellRenderer: CellRenderer = DefaultCellRenderer, getFooter: (DataFrame) -> String? = { "DataFrame [${it.size}]" }, @@ -620,25 +640,40 @@ public class DataFrameHtmlData( }, ) + public fun writeHtml(destination: File) { + destination.writeText(toString()) + } + + public fun writeHtml(destination: String) { + File(destination).writeText(toString()) + } + + public fun writeHtml(destination: Path) { + destination.writeText(toString()) + } + + @Deprecated(WRITE_HTML, ReplaceWith(WRITE_HTML_REPLACE), DeprecationLevel.ERROR) public fun writeHTML(destination: File) { destination.writeText(toString()) } + @Deprecated(WRITE_HTML, ReplaceWith(WRITE_HTML_REPLACE), DeprecationLevel.ERROR) public fun writeHTML(destination: String) { File(destination).writeText(toString()) } + @Deprecated(WRITE_HTML, ReplaceWith(WRITE_HTML_REPLACE), DeprecationLevel.ERROR) public fun writeHTML(destination: Path) { destination.writeText(toString()) } /** * Opens a new tab in your default browser. - * Consider [writeHTML] with the [HTML file auto-reload](https://www.jetbrains.com/help/idea/editing-html-files.html#ws_html_preview_output_procedure) feature of IntelliJ IDEA if you want to experiment with the output and run program multiple times + * Consider [writeHtml] with the [HTML file auto-reload](https://www.jetbrains.com/help/idea/editing-html-files.html#ws_html_preview_output_procedure) feature of IntelliJ IDEA if you want to experiment with the output and run program multiple times */ public fun openInBrowser() { val file = File.createTempFile("df_rendering", ".html") - writeHTML(file) + writeHtml(file) val uri = file.toURI() val desktop = Desktop.getDesktop() desktop.browse(uri) @@ -680,7 +715,7 @@ public class DataFrameHtmlData( /** * @return CSS and JS required to render DataFrame tables * Can be used as a starting point to create page with multiple tables - * @see DataFrame.toHTML + * @see DataFrame.toHtml * @see DataFrameHtmlData.plus */ public fun tableDefinitions(includeJs: Boolean = true, includeCss: Boolean = true): DataFrameHtmlData = diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/importDataSchema.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/importDataSchema.kt index 6bbfafa64e..cb46d8372a 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/importDataSchema.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/importDataSchema.kt @@ -2,10 +2,11 @@ package org.jetbrains.kotlinx.dataframe.jupyter import org.intellij.lang.annotations.Language import java.io.File +import java.net.URI import java.net.URL public class ImportDataSchema(public val url: URL) { - public constructor(path: String) : this(URL(path)) + public constructor(path: String) : this(URI(path).toURL()) public constructor(file: File) : this(file.toURI().toURL()) } @@ -47,7 +48,7 @@ internal val importDataSchema = } /** Import the type-only data schema from [path]. */ - fun importDataSchema(path: String, name: String): Unit = importDataSchema(URL(path), name) + fun importDataSchema(path: String, name: String): Unit = importDataSchema(URI(path).toURL(), name) /** Import the type-only data schema from [file]. */ fun importDataSchema(file: File, name: String): Unit = importDataSchema(file.toURI().toURL(), name) diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/util/deprecationMessages.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/util/deprecationMessages.kt index 94e6393e6b..bb6b33e912 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/util/deprecationMessages.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/util/deprecationMessages.kt @@ -95,6 +95,21 @@ internal const val MEAN_NO_SKIPNAN = "This function is just here for binary comp internal const val CONVERT_TO = "This to overload will be removed in favor of `asColumn`. $MESSAGE_0_16" internal const val CONVERT_TO_REPLACE = "this.asColumn(columnConverter)" +internal const val TO_HTML = "This function is replaced by `toHtml()`. $MESSAGE_0_16" +internal const val TO_HTML_REPLACE = "toHtml(configuration, cellRenderer, getFooter)" + +internal const val TO_STANDALONE_HTML = "This function is replaced by `toStandaloneHtml()`. $MESSAGE_0_16" +internal const val TO_STANDALONE_HTML_REPLACE = "toStandaloneHtml(configuration, cellRenderer, getFooter)" + +internal const val WRITE_HTML = "This function is replaced by `writeHtml()`. $MESSAGE_0_16" +internal const val WRITE_HTML_REPLACE = "writeHtml(destination)" + +internal const val CONVERT_TO_URL = "This function is replaced by `convertToUrl()`. $MESSAGE_0_16" +internal const val CONVERT_TO_URL_REPLACE = "convertToUrl()" + +internal const val TO_URL = "This function is replaced by `toUrl()`. $MESSAGE_0_16" +internal const val TO_URL_REPLACE = "toUrl()" + // endregion // region WARNING in 0.16, ERROR in 0.17 diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/explainer/PluginCallbackProxy.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/explainer/PluginCallbackProxy.kt index 0f6cafbbe5..2f90f193f5 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/explainer/PluginCallbackProxy.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/explainer/PluginCallbackProxy.kt @@ -29,7 +29,7 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnsResolver import org.jetbrains.kotlinx.dataframe.io.DataFrameHtmlData import org.jetbrains.kotlinx.dataframe.io.sessionId import org.jetbrains.kotlinx.dataframe.io.tableInSessionId -import org.jetbrains.kotlinx.dataframe.io.toHTML +import org.jetbrains.kotlinx.dataframe.io.toHtml import java.io.File annotation class TransformDataFrameExpressions @@ -122,7 +122,7 @@ object PluginCallbackProxy : PluginCallback { val destination = File("build/dataframes").also { it.mkdirs() } - output.writeHTML(File(destination, "$name.html")) + output.writeHtml(File(destination, "$name.html")) val korro = File("build/korroOutputLines").also { it.mkdirs() } @@ -150,7 +150,7 @@ object PluginCallbackProxy : PluginCallback { if (expressions.size == 1) { if (allow.any { expressions[0].source.contains(it) }) { val expression = expressions[0] - data += convertToHTML(expression.df) + data += convertToHtml(expression.df) } else { error("${expressions.joinToSource()} Sample without output or input (i.e. function returns some value)") } @@ -158,7 +158,7 @@ object PluginCallbackProxy : PluginCallback { for ((i, expression) in expressions.withIndex()) { when (i) { 0 -> { - val table = convertToHTML(expression.df) + val table = convertToHtml(expression.df) val description = table.copy( body = """ @@ -172,7 +172,7 @@ object PluginCallbackProxy : PluginCallback { } expressions.lastIndex -> { - val table = convertToHTML(expression.df) + val table = convertToHtml(expression.df) val description = table.copy( body = """ @@ -186,7 +186,7 @@ object PluginCallbackProxy : PluginCallback { } else -> { - val table = convertToHTML(expression.df) + val table = convertToHtml(expression.df) val description = table.copy( body = """ @@ -226,25 +226,25 @@ object PluginCallbackProxy : PluginCallback { } } -private fun convertToHTML(dataframeLike: Any): DataFrameHtmlData { - fun DataFrame<*>.toHTML() = toHTML(SamplesDisplayConfiguration, getFooter = WritersideFooter) +private fun convertToHtml(dataframeLike: Any): DataFrameHtmlData { + fun DataFrame<*>.toHtml() = this@toHtml.toHtml(SamplesDisplayConfiguration, getFooter = WritersideFooter) - fun FormattedFrame<*>.toHTML1() = toHTML(SamplesDisplayConfiguration) + fun FormattedFrame<*>.toHtml1() = toHtml(SamplesDisplayConfiguration) return when (dataframeLike) { - is Pivot<*> -> dataframeLike.frames().toDataFrame().toHTML() + is Pivot<*> -> dataframeLike.frames().toDataFrame().toHtml() - is ReducedPivot<*> -> dataframeLike.values().toDataFrame().toHTML() + is ReducedPivot<*> -> dataframeLike.values().toDataFrame().toHtml() - is PivotGroupBy<*> -> dataframeLike.frames().toHTML() + is PivotGroupBy<*> -> dataframeLike.frames().toHtml() - is ReducedPivotGroupBy<*> -> dataframeLike.values().toHTML() + is ReducedPivotGroupBy<*> -> dataframeLike.values().toHtml() - is SplitWithTransform<*, *, *> -> dataframeLike.into().toHTML() + is SplitWithTransform<*, *, *> -> dataframeLike.into().toHtml() - is Merge<*, *, *> -> dataframeLike.into("merged").toHTML() + is Merge<*, *, *> -> dataframeLike.into("merged").toHtml() - is Gather<*, *, *, *> -> dataframeLike.into("key", "value").toHTML() + is Gather<*, *, *, *> -> dataframeLike.into("key", "value").toHtml() is Update<*, *> -> dataframeLike.df.let { @@ -259,21 +259,21 @@ private fun convertToHTML(dataframeLike: Any): DataFrameHtmlData { it.with { background(rgb(152, 251, 152)) } - }.toHTML1() + }.toHtml1() is Convert<*, *> -> DataFrameHtmlData(body = "

${dataframeLike::class}

") - is FormattedFrame<*> -> dataframeLike.toHTML1() + is FormattedFrame<*> -> dataframeLike.toHtml1() - is GroupBy<*, *> -> dataframeLike.toDataFrame().toHTML() + is GroupBy<*, *> -> dataframeLike.toDataFrame().toHtml() - is AnyFrame -> dataframeLike.toHTML() + is AnyFrame -> dataframeLike.toHtml() - is AnyCol -> dataframeLike.toDataFrame().toHTML() + is AnyCol -> dataframeLike.toDataFrame().toHtml() - is DataRow<*> -> dataframeLike.toDataFrame().toHTML() + is DataRow<*> -> dataframeLike.toDataFrame().toHtml() - is Split<*, *> -> dataframeLike.toDataFrame().toHTML() + is Split<*, *> -> dataframeLike.toDataFrame().toHtml() else -> throw IllegalArgumentException("Unsupported type: ${dataframeLike::class}") } diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/rendering/RenderingTests.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/rendering/RenderingTests.kt index c2caec3de4..faa8dd72f6 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/rendering/RenderingTests.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/rendering/RenderingTests.kt @@ -31,8 +31,8 @@ import org.jetbrains.kotlinx.dataframe.io.print import org.jetbrains.kotlinx.dataframe.io.renderToString import org.jetbrains.kotlinx.dataframe.io.renderToStringTable import org.jetbrains.kotlinx.dataframe.io.tableInSessionId -import org.jetbrains.kotlinx.dataframe.io.toHTML -import org.jetbrains.kotlinx.dataframe.io.toStandaloneHTML +import org.jetbrains.kotlinx.dataframe.io.toHtml +import org.jetbrains.kotlinx.dataframe.io.toStandaloneHtml import org.jetbrains.kotlinx.dataframe.jupyter.DefaultCellRenderer import org.jetbrains.kotlinx.dataframe.jupyter.RenderedContent import org.jetbrains.kotlinx.dataframe.samples.api.TestBase @@ -72,21 +72,21 @@ class RenderingTests : TestBase() { @Test fun htmlTagsAreEscaped() { val df = dataFrameOf("name", "int")(" (12)", 1) - val html = df.toHTML().toString() + val html = df.toHtml().toString() html shouldContain "<Air France>" } @Test fun unicodeEscapeSequencesAreEscaped() { val df = dataFrameOf("content")("""Hello\nfrom \x and \y""") - val html = df.toHTML().toString() + val html = df.toHtml().toString() html shouldContain "Hello\nfrom \x and \y" } @Test fun `long text is trimmed without escaping`() { val df = dataFrameOf("text")("asdfkjasdlkjfhasljkddasdasdasdasdasdasdhf") - val html = df.toHTML().toString() + val html = df.toHtml().toString() html shouldNotContain "\\\\" html shouldNotContain """ } @@ -95,7 +95,7 @@ class RenderingTests : TestBase() { fun `non ascii text`() { val value = "Шёл Шива по шоссе, сокрушая сущее" val df = dataFrameOf("text")(value) - val script = df.toHTML().script + val script = df.toHtml().script script shouldContain value.escapeHTML() } @@ -118,13 +118,13 @@ class RenderingTests : TestBase() { .group("a", "b") .into("g") .add("a") { 1 } - .toHTML() + .toHtml() } @Test fun `render URL`() { val df = dataFrameOf("url")("https://api.github.com/orgs/JetBrains") - val html = df.parse().toHTML() + val html = df.parse().toHtml() html.toString() shouldNotContain RenderedContent::class.simpleName!! } @@ -133,7 +133,7 @@ class RenderingTests : TestBase() { val df = dataFrameOf("name", "parent", "type")("Boston (MA)", "123wazxdPag5", "Campus") .move("parent").into { "parent"["id"] } .group { all() }.into("Campus") - df.toHTML().print() + df.toHtml().print() } @Test @@ -144,14 +144,14 @@ class RenderingTests : TestBase() { dataFrameOf("col")(1.123) to "1${d}123", dataFrameOf("col")(1.0) to "1${d}0", ).forEach { (df, rendered) -> - df.toHTML().script shouldContain rendered + df.toHtml().script shouldContain rendered } } @Test fun `static rendering should be present`() { val df = dataFrameOf("a", "b")(listOf(1, 1), listOf(2, 4)) - val actualHtml = df.toHTML() + val actualHtml = df.toHtml() val body = actualHtml.body.lines().joinToString("") { it.trimStart() } @@ -216,9 +216,9 @@ class RenderingTests : TestBase() { val nestedFrame = dataFrameOf("a")(df) val configuration = DisplayConfiguration(enableFallbackStaticTables = false) tableInSessionId = 0 - val formattedHtml = formatted.toStandaloneHTML(configuration).toString() + val formattedHtml = formatted.toStandaloneHtml(configuration).toString() tableInSessionId = 0 - val regularHtml = nestedFrame.toStandaloneHTML(configuration).toString() + val regularHtml = nestedFrame.toStandaloneHtml(configuration).toString() formattedHtml.replace("api.FormattedFrame", "DataFrame") shouldBe regularHtml } @@ -226,7 +226,7 @@ class RenderingTests : TestBase() { @Test fun `render cell attributes for nested FormattedFrame`() { val df = dataFrameOf("a")(dataFrameOf("b")(1).format { all() }.with { background(green) }) - val html = df.toStandaloneHTML() + val html = df.toStandaloneHtml() html.toString() shouldInclude "style: \"background-color" } @@ -234,21 +234,21 @@ class RenderingTests : TestBase() { fun `render img`() { val src = "https://github.com/Kotlin/dataframe/blob/master/docs/StardustDocs/images/gettingStarted.png?raw=true" val df = dataFrameOf("img")(IMG(src)) - df.toStandaloneHTML().toString() shouldInclude + df.toStandaloneHtml().toString() shouldInclude """values: [""]""" } @Test fun `render custom content`() { val df = dataFrameOf("customUrl")(RenderedContent.media("""Click me!""")) - df.toStandaloneHTML().toString() shouldInclude + df.toStandaloneHtml().toString() shouldInclude """values: ["Click me!"]""" } @Test fun `render iframe content`() { val df = dataFrameOf("iframe")(IFRAME("http://example.com")) - df.toStandaloneHTML().toString() shouldInclude + df.toStandaloneHtml().toString() shouldInclude """values: ["