Skip to content

Commit 9727892

Browse files
committed
Merge branch 'master' into version-bumps
# Conflicts: # gradle/libs.versions.toml # plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/ConvenienceSchemaGeneratorPlugin.kt
2 parents 0f49f72 + 341365f commit 9727892

File tree

16 files changed

+137
-100
lines changed

16 files changed

+137
-100
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import org.jetbrains.kotlinx.dataframe.api.filter
88
import org.jetbrains.kotlinx.dataframe.api.map
99
import org.jetbrains.kotlinx.dataframe.api.schema
1010
import org.jetbrains.kotlinx.dataframe.api.take
11-
import org.jetbrains.kotlinx.dataframe.api.type
1211
import org.jetbrains.kotlinx.dataframe.columns.BaseColumn
1312
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
1413
import org.jetbrains.kotlinx.dataframe.columns.ColumnKind

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ public class AddDsl<T>(@PublishedApi internal val df: DataFrame<T>) : ColumnsCon
174174
noinline expression: RowExpression<T, R>
175175
): Boolean = add(df.mapToColumn(name, infer, expression))
176176

177-
public inline fun <reified R> expr(noinline expression: RowExpression<T, R>): DataColumn<R> {
178-
return df.mapToColumn("", Infer.Nulls, expression)
177+
public inline fun <reified R> expr(infer: Infer = Infer.Nulls, noinline expression: RowExpression<T, R>): DataColumn<R> {
178+
return df.mapToColumn("", infer, expression)
179179
}
180180

181181
public inline infix fun <reified R> String.from(noinline expression: RowExpression<T, R>): Boolean =

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ public abstract class CreateDataFrameDsl<T> : TraversePropertiesDsl {
153153
body: (TraversePropertiesDsl.() -> Unit)? = null,
154154
)
155155

156-
public inline fun <reified R> expr(noinline expression: (T) -> R): DataColumn<R> =
157-
source.map { expression(it) }.toColumn()
156+
public inline fun <reified R> expr(infer: Infer = Infer.Nulls, noinline expression: (T) -> R): DataColumn<R> =
157+
source.map { expression(it) }.toColumn(infer = infer)
158158

159159
public inline fun <reified R> add(name: String, noinline expression: (T) -> R): Unit =
160160
add(source.map { expression(it) }.toColumn(name, Infer.Nulls))
@@ -165,6 +165,9 @@ public abstract class CreateDataFrameDsl<T> : TraversePropertiesDsl {
165165
public inline infix fun <reified R> KProperty<R>.from(noinline expression: (T) -> R): Unit =
166166
add(columnName, expression)
167167

168+
public inline infix fun <reified R> String.from(inferType: InferType<T, R>): Unit =
169+
add(DataColumn.createWithTypeInference(this, source.map { inferType.expression(it) }))
170+
168171
public inline infix fun <reified R> KProperty<R>.from(inferType: InferType<T, R>): Unit =
169172
add(DataColumn.createWithTypeInference(columnName, source.map { inferType.expression(it) }))
170173

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/toDataFrame.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ class CreateDataFrameTests {
6060
res["e"].type() shouldBe typeOf<Int>()
6161
}
6262

63+
@Test
64+
fun `create column with infer type`() {
65+
val data: List<Any> = listOf(1, 2, 3)
66+
val res = data.toDataFrame {
67+
"e" from inferType { it }
68+
expr(infer = Infer.Type) { it } into "d"
69+
}
70+
71+
res["e"].type() shouldBe typeOf<Int>()
72+
res["e"].kind() shouldBe ColumnKind.Value
73+
74+
res["d"].type() shouldBe typeOf<Int>()
75+
res["d"].kind() shouldBe ColumnKind.Value
76+
}
77+
6378
@Test
6479
fun `preserve fields order`() {
6580
class B(val x: Int, val c: String, d: Double) {

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/CodeGenerationTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class CodeGenerationTests : DataFrameJupyterTest() {
88

99
private fun Code.checkCompilation() {
1010
lines().forEach {
11-
exec(it)
11+
execRendered(it)
1212
}
1313
}
1414

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/JupyterCodegenTests.kt

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
1919
@Test
2020
fun `codegen adding column with generic type function`() {
2121
@Language("kts")
22-
val res1 = exec(
22+
val res1 = execRendered(
2323
"""
2424
fun <T> AnyFrame.addValue(value: T) = add("value") { listOf(value) }
2525
val df = dataFrameOf("a")(1).addValue(2)
@@ -36,7 +36,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
3636
@Test
3737
fun `Don't inherit from data class`() {
3838
@Language("kts")
39-
val res1 = exec(
39+
val res1 = execRendered(
4040
"""
4141
@DataSchema
4242
data class A(val a: Int)
@@ -57,7 +57,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
5757
@Test
5858
fun `Don't inherit from non open class`() {
5959
@Language("kts")
60-
val res1 = exec(
60+
val res1 = execRendered(
6161
"""
6262
@DataSchema
6363
class A(val a: Int)
@@ -78,7 +78,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
7878
@Test
7979
fun `Don't inherit from open class`() {
8080
@Language("kts")
81-
val res1 = exec(
81+
val res1 = execRendered(
8282
"""
8383
@DataSchema
8484
open class A(val a: Int)
@@ -99,7 +99,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
9999
@Test
100100
fun `Do inherit from open interface`() {
101101
@Language("kts")
102-
val res1 = exec(
102+
val res1 = execRendered(
103103
"""
104104
@DataSchema
105105
interface A { val a: Int }
@@ -120,7 +120,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
120120
@Test
121121
fun `codegen for enumerated frames`() {
122122
@Language("kts")
123-
val res1 = exec(
123+
val res1 = execRendered(
124124
"""
125125
val names = (0..2).map { it.toString() }
126126
val df = dataFrameOf(names)(1, 2, 3)
@@ -136,7 +136,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
136136
@Test
137137
fun `codegen for complex column names`() {
138138
@Language("kts")
139-
val res1 = exec(
139+
val res1 = execRendered(
140140
"""
141141
val df = DataFrame.readDelimStr("[a], (b), {c}\n1, 2, 3")
142142
df
@@ -145,7 +145,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
145145
res1.shouldBeInstanceOf<MimeTypedResult>()
146146

147147
@Language("kts")
148-
val res2 = exec(
148+
val res2 = execRendered(
149149
"""listOf(df.`{a}`[0], df.`(b)`[0], df.`{c}`[0])"""
150150
)
151151
res2 shouldBe listOf(1, 2, 3)
@@ -154,7 +154,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
154154
@Test
155155
fun `codegen for '$' that is interpolator in kotlin string literals`() {
156156
@Language("kts")
157-
val res1 = exec(
157+
val res1 = execRendered(
158158
"""
159159
val df = DataFrame.readDelimStr("\${'$'}id\n1")
160160
df
@@ -163,7 +163,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
163163
res1.shouldBeInstanceOf<MimeTypedResult>()
164164

165165
@Language("kts")
166-
val res2 = exec(
166+
val res2 = execRendered(
167167
"listOf(df.`\$id`[0])"
168168
)
169169
res2 shouldBe listOf(1)
@@ -172,7 +172,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
172172
@Test
173173
fun `codegen for backtick that is forbidden in kotlin identifiers`() {
174174
@Language("kts")
175-
val res1 = exec(
175+
val res1 = execRendered(
176176
"""
177177
val df = DataFrame.readDelimStr("Day`s\n1")
178178
df
@@ -182,7 +182,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
182182
println(res1.entries.joinToString())
183183

184184
@Language("kts")
185-
val res2 = exec(
185+
val res2 = execRendered(
186186
"listOf(df.`Day's`[0])"
187187
)
188188
res2 shouldBe listOf(1)
@@ -193,7 +193,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
193193
val forbiddenChar = ";"
194194

195195
@Language("kts")
196-
val res1 = exec(
196+
val res1 = execRendered(
197197
"""
198198
val df = DataFrame.readDelimStr("Test$forbiddenChar\n1")
199199
df
@@ -203,7 +203,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
203203
println(res1.entries.joinToString())
204204

205205
@Language("kts")
206-
val res2 = exec(
206+
val res2 = execRendered(
207207
"listOf(df.`Test `[0])"
208208
)
209209
res2 shouldBe listOf(1)
@@ -214,7 +214,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
214214
val forbiddenChar = "\\\\"
215215

216216
@Language("kts")
217-
val res1 = exec(
217+
val res1 = execRendered(
218218
"""
219219
val df = DataFrame.readDelimStr("Test$forbiddenChar\n1")
220220
df
@@ -224,7 +224,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
224224
println(res1.entries.joinToString())
225225

226226
@Language("kts")
227-
val res2 = exec(
227+
val res2 = execRendered(
228228
"listOf(df.`Test `[0])"
229229
)
230230
res2 shouldBe listOf(1)
@@ -233,7 +233,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
233233
@Test
234234
fun `generic interface`() {
235235
@Language("kts")
236-
val res1 = exec(
236+
val res1 = execRendered(
237237
"""
238238
@DataSchema
239239
interface Generic<T> {
@@ -244,7 +244,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
244244
res1.shouldBeInstanceOf<Unit>()
245245

246246
@Language("kts")
247-
val res2 = exec(
247+
val res2 = execRendered(
248248
"""
249249
val <T> ColumnsContainer<Generic<T>>.test1: DataColumn<T> get() = field
250250
val <T> DataRow<Generic<T>>.test2: T get() = field
@@ -256,7 +256,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
256256
@Test
257257
fun `generic interface with upper bound`() {
258258
@Language("kts")
259-
val res1 = exec(
259+
val res1 = execRendered(
260260
"""
261261
@DataSchema
262262
interface Generic <T : String> {
@@ -267,7 +267,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
267267
res1.shouldBeInstanceOf<Unit>()
268268

269269
@Language("kts")
270-
val res2 = exec(
270+
val res2 = execRendered(
271271
"""
272272
val <T : String> ColumnsContainer<Generic<T>>.test1: DataColumn<T> get() = field
273273
val <T : String> DataRow<Generic<T>>.test2: T get() = field
@@ -279,7 +279,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
279279
@Test
280280
fun `generic interface with variance and user type in type parameters`() {
281281
@Language("kts")
282-
val res1 = exec(
282+
val res1 = execRendered(
283283
"""
284284
interface UpperBound
285285
@@ -292,7 +292,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
292292
res1.shouldBeInstanceOf<Unit>()
293293

294294
@Language("kts")
295-
val res2 = exec(
295+
val res2 = execRendered(
296296
"""
297297
val <T : UpperBound> ColumnsContainer<Generic<T>>.test1: DataColumn<T> get() = field
298298
val <T : UpperBound> DataRow<Generic<T>>.test2: T get() = field
@@ -304,7 +304,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
304304
@Test
305305
fun `generate a new marker when dataframe marker is not a data schema so that columns are accessible with extensions`() {
306306
@Language("kts")
307-
val a = exec(
307+
val a = execRendered(
308308
"""
309309
enum class State {
310310
Idle, Productive, Maintenance
@@ -328,7 +328,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
328328
)
329329
shouldNotThrowAny {
330330
@Language("kts")
331-
val b = exec(
331+
val b = execRendered(
332332
"""
333333
events.toolId
334334
events.state

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/RenderingTests.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class RenderingTests : JupyterReplTestCase() {
3232
html shouldContain "Bill"
3333

3434
@Language("kts")
35-
val useRes = exec(
35+
val useRes = execRendered(
3636
"""
3737
USE {
3838
render<Int> { (it * 2).toString() }
@@ -73,7 +73,7 @@ class RenderingTests : JupyterReplTestCase() {
7373
fun execSimpleDf() = execHtml("""dataFrameOf("a", "b")(1, 2, 3, 4)""")
7474

7575
val htmlLight = execSimpleDf()
76-
val r1 = exec("notebook.changeColorScheme(ColorScheme.DARK); 1")
76+
val r1 = execRendered("notebook.changeColorScheme(ColorScheme.DARK); 1")
7777
val htmlDark = execSimpleDf()
7878

7979
r1 shouldBe 1
@@ -106,7 +106,7 @@ class RenderingTests : JupyterReplTestCase() {
106106
* @return the parsed DataFrame result as a `JsonObject`
107107
*/
108108
private fun executeScriptAndParseDataframeResult(@Language("kts") script: String): JsonObject {
109-
val result = exec<MimeTypedResult>(script)
109+
val result = execRendered<MimeTypedResult>(script)
110110
return parseDataframeJson(result)
111111
}
112112

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/SampleNotebooksTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class SampleNotebooksTests : DataFrameJupyterTest() {
9595
val codeToExecute = replacer.replace(code)
9696

9797
println("Executing code:\n$codeToExecute")
98-
val cellResult = exec(codeToExecute)
98+
val cellResult = execRendered(codeToExecute)
9999
println(cellResult)
100100
}
101101
} finally {

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/DataFrameTests.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import org.jetbrains.kotlinx.dataframe.annotations.ColumnName
1515
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
1616
import org.jetbrains.kotlinx.dataframe.api.ExcessiveColumns
1717
import org.jetbrains.kotlinx.dataframe.api.GroupBy
18+
import org.jetbrains.kotlinx.dataframe.api.Infer
1819
import org.jetbrains.kotlinx.dataframe.api.ParserOptions
1920
import org.jetbrains.kotlinx.dataframe.api.add
2021
import org.jetbrains.kotlinx.dataframe.api.addAll
@@ -182,6 +183,7 @@ import org.jetbrains.kotlinx.dataframe.size
182183
import org.jetbrains.kotlinx.dataframe.type
183184
import org.jetbrains.kotlinx.dataframe.typeClass
184185
import org.junit.Test
186+
import java.lang.reflect.Type
185187
import java.math.BigDecimal
186188
import java.time.LocalDate
187189
import kotlin.reflect.jvm.jvmErasure
@@ -919,6 +921,15 @@ class DataFrameTests : BaseTest() {
919921
}
920922
}
921923

924+
@Test
925+
fun `add several columns with type inference`() {
926+
val f: Any = 123
927+
val df = typed.add {
928+
expr(infer = Infer.Type) { f } into "f"
929+
}
930+
df["f"].type() shouldBe typeOf<Int>()
931+
}
932+
922933
@Test
923934
fun `remove one column`() {
924935
val expected = listOf("name", "city", "weight")

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/HtmlRenderingTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import org.jetbrains.kotlinx.dataframe.api.group
88
import org.jetbrains.kotlinx.dataframe.api.into
99
import org.jetbrains.kotlinx.dataframe.api.parse
1010
import org.jetbrains.kotlinx.dataframe.io.toStandaloneHTML
11-
import org.jetbrains.kotlinx.jupyter.findNthSubstring
11+
import org.jetbrains.kotlinx.jupyter.util.findNthSubstring
1212
import org.junit.Ignore
1313
import org.junit.Test
1414
import java.awt.Desktop

0 commit comments

Comments
 (0)