Skip to content

Commit c2786c2

Browse files
committed
starting full deprecation cycle for Instant -> StdlibInstant/DeprecatedInstant -> Instant. Also ParserOptions.parseExperimentalInstant
1 parent c9bdabe commit c2786c2

File tree

30 files changed

+1177
-327
lines changed

30 files changed

+1177
-327
lines changed

build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ allprojects {
188188
options.release.set(8)
189189
}
190190
}
191+
tasks.withType<KotlinCompile> {
192+
compilerOptions {
193+
// enables support for kotlin.time.Instant as kotlinx.datetime.Instant was deprecated
194+
optIn.add("kotlin.time.ExperimentalTime")
195+
}
196+
}
191197

192198
// Attempts to configure ktlint for each sub-project that uses the plugin
193199
afterEvaluate {

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/convert.kt

Lines changed: 266 additions & 33 deletions
Large diffs are not rendered by default.

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/format.kt

Lines changed: 33 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
1919
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
2020
import org.jetbrains.kotlinx.dataframe.dataTypes.IFRAME
2121
import org.jetbrains.kotlinx.dataframe.dataTypes.IMG
22-
import org.jetbrains.kotlinx.dataframe.documentation.ExportAsHtml
2322
import org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns
2423
import org.jetbrains.kotlinx.dataframe.documentation.SelectingRows
2524
import org.jetbrains.kotlinx.dataframe.impl.api.MergedAttributes
@@ -34,6 +33,10 @@ import org.jetbrains.kotlinx.dataframe.io.toHtml
3433
import org.jetbrains.kotlinx.dataframe.io.toStandaloneHtml
3534
import org.jetbrains.kotlinx.dataframe.jupyter.RenderedContent.Companion.media
3635
import org.jetbrains.kotlinx.dataframe.util.DEPRECATED_ACCESS_API
36+
import org.jetbrains.kotlinx.dataframe.util.FORMATTING_DSL
37+
import org.jetbrains.kotlinx.dataframe.util.FORMATTING_DSL_REPLACE
38+
import org.jetbrains.kotlinx.dataframe.util.RGB_COLOR
39+
import org.jetbrains.kotlinx.dataframe.util.RGB_COLOR_REPLACE
3740
import kotlin.reflect.KProperty
3841

3942
// region docs
@@ -214,82 +217,6 @@ internal interface FormatDocs {
214217
*/
215218
interface Grammar {
216219

217-
/**
218-
* ### Definitions:
219-
* `cellFormatter: `[FormattingDsl][org.jetbrains.kotlinx.dataframe.api.FormatDocs.Grammar.FormattingDslGrammarDef]`.(cell: C) -> `[CellAttributes][org.jetbrains.kotlinx.dataframe.api.CellAttributes]`?`
220-
*
221-
* &nbsp;&nbsp;&nbsp;&nbsp;
222-
*
223-
* `rowColFormatter: `[FormattingDsl][org.jetbrains.kotlinx.dataframe.api.FormatDocs.Grammar.FormattingDslGrammarDef]`.(row: `[DataRow][org.jetbrains.kotlinx.dataframe.DataRow]`<T>, col: `[DataColumn][org.jetbrains.kotlinx.dataframe.DataColumn]`<C>) -> `[CellAttributes][org.jetbrains.kotlinx.dataframe.api.CellAttributes]`?`
224-
*
225-
* ### Notation:
226-
*
227-
* [**format**][DataFrame.format]**` { `**[`columns`][SelectingColumns]**` }`**
228-
*
229-
* &nbsp;&nbsp;&nbsp;&nbsp;
230-
* `[ `__`.`__[**`where`**][FormatClause.where]**` { `**[`filter`][SelectingRows.RowValueCondition]`: `[`RowValueFilter`][RowValueFilter]**` } `**`]`
231-
*
232-
* &nbsp;&nbsp;&nbsp;&nbsp;
233-
* `[ `__`.`__[**`at`**][FormatClause.at]**`(`**`rowIndices: `[Collection][Collection]`<`[Int][Int]`> | `[IntRange][IntRange]` | `**`vararg`**` `[Int][Int]**`)`**` ]`
234-
*
235-
* &nbsp;&nbsp;&nbsp;&nbsp;
236-
* `[ `__`.`__[**`notNull`**][FormatClause.notNull]**`()`**` ]`
237-
*
238-
* &nbsp;&nbsp;&nbsp;&nbsp;
239-
* __`.`__[**`with`**][FormatClause.with]**` { `**[cellFormatter][org.jetbrains.kotlinx.dataframe.api.FormatDocs.Grammar.CellFormatterDef]**` }`**
240-
*
241-
* &nbsp;&nbsp;&nbsp;&nbsp;
242-
* `| `__`.`__[**`notNull`**][FormatClause.notNull]**` { `**[cellFormatter][org.jetbrains.kotlinx.dataframe.api.FormatDocs.Grammar.CellFormatterDef]**` }`**
243-
*
244-
* &nbsp;&nbsp;&nbsp;&nbsp;
245-
* `| `__`.`__[**`perRowCol`**][FormatClause.perRowCol]**` { `**[rowColFormatter][org.jetbrains.kotlinx.dataframe.api.FormatDocs.Grammar.RowColFormatterDef]**` }`**
246-
*
247-
* &nbsp;&nbsp;&nbsp;&nbsp;
248-
* `| `__`.`__[**`linearBg`**][FormatClause.linearBg]**`(`**`from: `[Pair][Pair]`<`[Number][Number]`, `[RgbColor][RgbColor]`>`**`,`**` to: `[Pair][Pair]`<`[Number][Number]`, `[RgbColor][RgbColor]`>`**`)`**
249-
*
250-
* `[ `__`.`__[**format**][FormattedFrame.format]` ↺ ]`
251-
*
252-
* &nbsp;&nbsp;&nbsp;&nbsp;
253-
*
254-
* ## Formatting DSL Grammar
255-
*
256-
* ### Definitions:
257-
* `cellAttributes: `[CellAttributes][org.jetbrains.kotlinx.dataframe.api.CellAttributes]
258-
*
259-
* &nbsp;&nbsp;&nbsp;&nbsp;
260-
*
261-
* `color: `[RgbColor][org.jetbrains.kotlinx.dataframe.api.RgbColor]
262-
*
263-
* ### Notation:
264-
* _- Returning [CellAttributes][org.jetbrains.kotlinx.dataframe.api.CellAttributes]_:
265-
*
266-
* [cellAttributes][org.jetbrains.kotlinx.dataframe.api.FormatDocs.Grammar.CellAttributesDef]` `[**`and`**][org.jetbrains.kotlinx.dataframe.api.CellAttributes.and]` `[cellAttributes][org.jetbrains.kotlinx.dataframe.api.FormatDocs.Grammar.CellAttributesDef]
267-
*
268-
* `| `[**`italic`**][org.jetbrains.kotlinx.dataframe.api.FormattingDsl.italic]` | `[**`bold`**][org.jetbrains.kotlinx.dataframe.api.FormattingDsl.bold]` | `[**`underline`**][org.jetbrains.kotlinx.dataframe.api.FormattingDsl.underline]
269-
*
270-
* `| `[**`background`**][org.jetbrains.kotlinx.dataframe.api.FormattingDsl.background]**`(`**[color][org.jetbrains.kotlinx.dataframe.api.FormatDocs.Grammar.RgbColorDef]**`)`**
271-
*
272-
* `| `[**`background`**][org.jetbrains.kotlinx.dataframe.api.FormattingDsl.background]**`(`**`r: `[Short][Short]**`,`**` g: `[Short][Short]**`,`**` b: `[Short][Short]**`)`**
273-
*
274-
* `| `[**`linearBg`**][org.jetbrains.kotlinx.dataframe.api.FormattingDsl.linearBg]**`(`**`value: `[Number][Number]**`,`**` from: `[Pair][Pair]`<`[Number][Number]`, `[RgbColor][org.jetbrains.kotlinx.dataframe.api.RgbColor]`>`**`,`**` to: `[Pair][Pair]`<`[Number][Number]`, `[RgbColor][org.jetbrains.kotlinx.dataframe.api.RgbColor]`>`**`)`**
275-
*
276-
* `| `[**`textColor`**][org.jetbrains.kotlinx.dataframe.api.FormattingDsl.textColor]**`(`**[color][org.jetbrains.kotlinx.dataframe.api.FormatDocs.Grammar.RgbColorDef]**`)`**
277-
*
278-
* `| `[**`textColor`**][org.jetbrains.kotlinx.dataframe.api.FormattingDsl.textColor]**`(`**`r: `[Short][Short]**`,`**` g: `[Short][Short]**`,`**` b: `[Short][Short]**`)`**
279-
*
280-
* `| `[**`attr`**][org.jetbrains.kotlinx.dataframe.api.FormattingDsl.attr]**`(`**`name: `[String][String]**`,`**` value: `[String][String]**`)`**
281-
*
282-
* _- Returning [RgbColor][org.jetbrains.kotlinx.dataframe.api.RgbColor]:_
283-
*
284-
* [**`black`**][org.jetbrains.kotlinx.dataframe.api.FormattingDsl.black]` | `[**`white`**][org.jetbrains.kotlinx.dataframe.api.FormattingDsl.white]` | `[**`green`**][org.jetbrains.kotlinx.dataframe.api.FormattingDsl.green]` | `[**`red`**][org.jetbrains.kotlinx.dataframe.api.FormattingDsl.red]` | `[**`blue`**][org.jetbrains.kotlinx.dataframe.api.FormattingDsl.blue]` | `[**`gray`**][org.jetbrains.kotlinx.dataframe.api.FormattingDsl.gray]` | `[**`darkGray`**][org.jetbrains.kotlinx.dataframe.api.FormattingDsl.darkGray]` | `[**`lightGray`**][org.jetbrains.kotlinx.dataframe.api.FormattingDsl.lightGray]
285-
*
286-
* `| `[**`rgb`**][org.jetbrains.kotlinx.dataframe.api.FormattingDsl.rgb]**`(`**`r: `[Short][Short]**`,`**` g: `[Short][Short]**`,`**` b: `[Short][Short]**`)`**
287-
*
288-
* `| `[**`linear`**][org.jetbrains.kotlinx.dataframe.api.FormattingDsl.linear]**`(`**`value: `[Number][Number]**`,`**` from: `[Pair][Pair]`<`[Number][Number]`, `[RgbColor][org.jetbrains.kotlinx.dataframe.api.RgbColor]`>`**`,`**` to: `[Pair][Pair]`<`[Number][Number]`, `[RgbColor][org.jetbrains.kotlinx.dataframe.api.RgbColor]`>`**`)`**
289-
*/
290-
@ExportAsHtml
291-
interface ForHtml
292-
293220
/**
294221
* ## Formatting DSL Grammar
295222
*
@@ -1134,14 +1061,18 @@ public typealias CellFormatter<C> = FormattingDsl.(cell: C) -> CellAttributes?
11341061
*
11351062
* Call [toHtml] or [toStandaloneHtml] to get the HTML representation of the [DataFrame].
11361063
*
1064+
* In Jupyter kernel (Kotlin Notebook) environments, you can often output this class directly.
1065+
* Use [toHtml] or [toStandaloneHtml] when this produces unexpected results.
1066+
*
11371067
* You can apply further formatting to this [FormattedFrame] by calling [format()][FormattedFrame.format] once again.
11381068
*/
11391069
public class FormattedFrame<T>(internal val df: DataFrame<T>, internal val formatter: RowColFormatter<T, *>? = null) {
11401070

11411071
/**
11421072
* Returns a [DataFrameHtmlData] without additional definitions.
1143-
* Can be rendered in Jupyter kernel (Notebook) environments or other environments that already have
1073+
* Can be rendered in Jupyter kernel (Kotlin Notebook) environments or other environments that already have
11441074
* CSS- and script definitions for DataFrame.
1075+
*
11451076
* Use [toStandaloneHtml] if you need the [DataFrameHtmlData] to include CSS- and script definitions.
11461077
*
11471078
* By default, cell content is formatted as text
@@ -1157,6 +1088,8 @@ public class FormattedFrame<T>(internal val df: DataFrame<T>, internal val forma
11571088
/**
11581089
* Returns a [DataFrameHtmlData] with CSS- and script definitions for DataFrame.
11591090
*
1091+
* Use [toHtml] if you don't need the [DataFrameHtmlData] to include CSS- and script definitions.
1092+
*
11601093
* The [DataFrameHtmlData] can be saved as an *.html file and displayed in the browser.
11611094
* If you save it as a file and find it in the project tree,
11621095
* the ["Open in browser"](https://www.jetbrains.com/help/idea/editing-html-files.html#ws_html_preview_output_procedure)
@@ -1165,6 +1098,10 @@ public class FormattedFrame<T>(internal val df: DataFrame<T>, internal val forma
11651098
* By default, cell content is formatted as text
11661099
* Use [RenderedContent.media][media] or [IMG], [IFRAME] if you need custom HTML inside a cell.
11671100
*
1101+
* __NOTE:__ In Kotlin Notebook, output [FormattedFrame] directly, or use [toHtml],
1102+
* as that environment already has CSS- and script definitions for DataFrame.
1103+
* Using [toStandaloneHtml] might produce unexpected results.
1104+
*
11681105
* @param [configuration] The [DisplayConfiguration] to use as a base for this [FormattedFrame].
11691106
* Default: [DisplayConfiguration.DEFAULT].
11701107
* @see toHtml
@@ -1213,3 +1150,21 @@ public class FormatClause<T, C>(
12131150
}
12141151

12151152
// endregion
1153+
1154+
// region Deprecated
1155+
1156+
@Deprecated(
1157+
message = FORMATTING_DSL,
1158+
replaceWith = ReplaceWith(FORMATTING_DSL_REPLACE),
1159+
level = DeprecationLevel.ERROR,
1160+
)
1161+
public typealias FormattingDSL = FormattingDsl
1162+
1163+
@Deprecated(
1164+
message = RGB_COLOR,
1165+
replaceWith = ReplaceWith(RGB_COLOR_REPLACE),
1166+
level = DeprecationLevel.ERROR,
1167+
)
1168+
public typealias RGBColor = RgbColor
1169+
1170+
// endregion

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/parse.kt

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ public interface GlobalParserOptions {
8585
* In notebooks, add `-opt-in=kotlin.uuid.ExperimentalUuidApi` to the compiler arguments.
8686
*/
8787
public var parseExperimentalUuid: Boolean
88+
89+
/**
90+
* Whether to allow parsing to the experimental [kotlin.time.Instant] type.
91+
* By default, this is false and instants are recognized as the deprecated [kotlinx.datetime.Instant] type (#1350).
92+
*
93+
* NOTE: Interacting with an [Instant][kotlin.time.Instant] in your code might require
94+
* `@`[OptIn][OptIn]`(`[ExperimentalTime][kotlin.time.ExperimentalTime]`::class)`.
95+
* In notebooks, add `-opt-in=kotlin.time.ExperimentalTime` to the compiler arguments.
96+
*/
97+
public var parseExperimentalInstant: Boolean
8898
}
8999

90100
/**
@@ -118,6 +128,11 @@ public interface GlobalParserOptions {
118128
* NOTE: Interacting with a [Uuid][Uuid] in your code might require
119129
* `@`[OptIn][OptIn]`(`[ExperimentalUuidApi][ExperimentalUuidApi]`::class)`.
120130
* In notebooks, add `-opt-in=kotlin.uuid.ExperimentalUuidApi` to the compiler arguments.
131+
* @param parseExperimentalInstant whether to allow parsing to the experimental [kotlin.time.Instant] type.
132+
* By default, this is false and instants are recognized as the deprecated [kotlinx.datetime.Instant] type (#1350).
133+
* NOTE: Interacting with an [Instant][kotlin.time.Instant] in your code might require
134+
* `@`[OptIn][OptIn]`(`[ExperimentalTime][kotlin.time.ExperimentalTime]`::class)`.
135+
* In notebooks, add `-opt-in=kotlin.time.ExperimentalTime` to the compiler arguments.
121136
*/
122137
public class ParserOptions(
123138
public val locale: Locale? = null,
@@ -128,6 +143,7 @@ public class ParserOptions(
128143
public val skipTypes: Set<KType>? = null,
129144
public val useFastDoubleParser: Boolean? = null,
130145
public val parseExperimentalUuid: Boolean? = null,
146+
public val parseExperimentalInstant: Boolean? = null,
131147
) {
132148

133149
/** For binary compatibility. */
@@ -150,6 +166,7 @@ public class ParserOptions(
150166
skipTypes = skipTypes,
151167
useFastDoubleParser = useFastDoubleParser,
152168
parseExperimentalUuid = null,
169+
parseExperimentalInstant = null,
153170
)
154171

155172
/** For binary compatibility. */
@@ -170,6 +187,7 @@ public class ParserOptions(
170187
skipTypes = null,
171188
useFastDoubleParser = null,
172189
parseExperimentalUuid = null,
190+
parseExperimentalInstant = null,
173191
)
174192

175193
/** For binary compatibility. */
@@ -193,6 +211,7 @@ public class ParserOptions(
193211
skipTypes = skipTypes,
194212
useFastDoubleParser = useFastDoubleParser,
195213
parseExperimentalUuid = null,
214+
parseExperimentalInstant = null,
196215
)
197216

198217
/** For binary compatibility. */
@@ -214,6 +233,7 @@ public class ParserOptions(
214233
skipTypes = skipTypes,
215234
useFastDoubleParser = useFastDoubleParser,
216235
parseExperimentalUuid = null,
236+
parseExperimentalInstant = null,
217237
)
218238

219239
internal fun getDateTimeFormatter(): DateTimeFormatter? =
@@ -232,6 +252,7 @@ public class ParserOptions(
232252
skipTypes: Set<KType>? = this.skipTypes,
233253
useFastDoubleParser: Boolean? = this.useFastDoubleParser,
234254
parseExperimentalUuid: Boolean? = this.parseExperimentalUuid,
255+
parseExperimentalInstant: Boolean? = this.parseExperimentalInstant,
235256
): ParserOptions =
236257
ParserOptions(
237258
locale = locale,
@@ -241,6 +262,7 @@ public class ParserOptions(
241262
skipTypes = skipTypes,
242263
useFastDoubleParser = useFastDoubleParser,
243264
parseExperimentalUuid = parseExperimentalUuid,
265+
parseExperimentalInstant = parseExperimentalInstant,
244266
)
245267

246268
override fun equals(other: Any?): Boolean {
@@ -256,6 +278,7 @@ public class ParserOptions(
256278
if (nullStrings != other.nullStrings) return false
257279
if (skipTypes != other.skipTypes) return false
258280
if (parseExperimentalUuid != other.parseExperimentalUuid) return false
281+
if (parseExperimentalInstant != other.parseExperimentalInstant) return false
259282

260283
return true
261284
}
@@ -268,11 +291,12 @@ public class ParserOptions(
268291
result = 31 * result + (nullStrings?.hashCode() ?: 0)
269292
result = 31 * result + (skipTypes?.hashCode() ?: 0)
270293
result = 31 * result + (parseExperimentalUuid?.hashCode() ?: 0)
294+
result = 31 * result + (parseExperimentalInstant?.hashCode() ?: 0)
271295
return result
272296
}
273297

274298
override fun toString(): String =
275-
"ParserOptions(locale=$locale, dateTimeFormatter=$dateTimeFormatter, dateTimePattern=$dateTimePattern, nullStrings=$nullStrings, skipTypes=$skipTypes, useFastDoubleParser=$useFastDoubleParser, parseExperimentalUuid=$parseExperimentalUuid)"
299+
"ParserOptions(locale=$locale, dateTimeFormatter=$dateTimeFormatter, dateTimePattern=$dateTimePattern, nullStrings=$nullStrings, skipTypes=$skipTypes, useFastDoubleParser=$useFastDoubleParser, parseExperimentalUuid=$parseExperimentalUuid, parseExperimentalInstant=$parseExperimentalInstant)"
276300
}
277301

278302
/** Tries to parse a column of strings into a column of a different type.

0 commit comments

Comments
 (0)