Skip to content

Commit 1fd3cd5

Browse files
committed
Merge branch 'refs/heads/master' into kdoc-fixes
2 parents b40340f + 195a305 commit 1fd3cd5

File tree

23 files changed

+237
-95
lines changed

23 files changed

+237
-95
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: "Validate Gradle Wrapper"
2+
on: [push, pull_request]
3+
4+
jobs:
5+
validation:
6+
name: "Validation"
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- uses: gradle/wrapper-validation-action@v2

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public fun <G> GroupBy<*, G>.pivotCounts(vararg columns: KProperty<*>, inward: B
148148

149149
// region pivot
150150

151-
public fun <T> AggregateGroupedDsl<T>.pivot(inward: Boolean = true, columns: ColumnsSelector<T, *>): PivotGroupBy<T> =
151+
public fun <T> AggregateGroupedDsl<T>.pivot(inward: Boolean = true, columns: PivotColumnsSelector<T, *>): PivotGroupBy<T> =
152152
PivotInAggregateImpl(this, columns, inward)
153153

154154
public fun <T> AggregateGroupedDsl<T>.pivot(vararg columns: String, inward: Boolean = true): PivotGroupBy<T> =

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@ package org.jetbrains.kotlinx.dataframe.api
33
import org.jetbrains.kotlinx.dataframe.DataColumn
44
import org.jetbrains.kotlinx.dataframe.DataFrame
55
import org.jetbrains.kotlinx.dataframe.indices
6+
import kotlin.random.Random
67

78
// region DataColumn
89

10+
public fun <T> DataColumn<T>.shuffle(random: Random): DataColumn<T> = get(indices.shuffled(random))
11+
912
public fun <T> DataColumn<T>.shuffle(): DataColumn<T> = get(indices.shuffled())
1013

1114
// endregion
1215

1316
// region DataFrame
1417

18+
public fun <T> DataFrame<T>.shuffle(random: Random): DataFrame<T> = getRows(indices.shuffled(random))
19+
1520
public fun <T> DataFrame<T>.shuffle(): DataFrame<T> = getRows(indices.shuffled())
1621

1722
// endregion

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/PivotInAggregateImpl.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import org.jetbrains.kotlinx.dataframe.ColumnsSelector
44
import org.jetbrains.kotlinx.dataframe.DataFrame
55
import org.jetbrains.kotlinx.dataframe.aggregation.AggregateBody
66
import org.jetbrains.kotlinx.dataframe.aggregation.AggregateGroupedDsl
7+
import org.jetbrains.kotlinx.dataframe.api.PivotColumnsSelector
78
import org.jetbrains.kotlinx.dataframe.api.PivotGroupBy
89
import org.jetbrains.kotlinx.dataframe.impl.api.AggregatedPivot
910
import org.jetbrains.kotlinx.dataframe.impl.api.aggregatePivot
1011
import org.jetbrains.kotlinx.dataframe.impl.columns.toColumnSet
1112

1213
internal data class PivotInAggregateImpl<T>(
1314
val aggregator: AggregateGroupedDsl<T>,
14-
val columns: ColumnsSelector<T, *>,
15+
val columns: PivotColumnsSelector<T, *>,
1516
val inward: Boolean?,
1617
val default: Any? = null
1718
) : PivotGroupBy<T>, AggregatableInternal<T> {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@ internal object Parsers : GlobalParserOptions {
248248
parser
249249
},
250250

251-
// kotlin.time.duration
251+
// kotlin.time.Duration
252252
stringParser { catchSilent { Duration.parse(it) } },
253253

254-
// java.time.duration
254+
// java.time.Duration
255255
stringParser { catchSilent { java.time.Duration.parse(it) } },
256256

257257
// java.time.LocalTime

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,8 @@ import org.jetbrains.kotlinx.dataframe.impl.renderType
4545
import org.jetbrains.kotlinx.dataframe.io.DataFrameHtmlData
4646
import org.jetbrains.kotlinx.dataframe.io.SupportedCodeGenerationFormat
4747
import org.jetbrains.kotlinx.dataframe.io.supportedFormats
48-
import org.jetbrains.kotlinx.jupyter.api.HTML
49-
import org.jetbrains.kotlinx.jupyter.api.JupyterClientType
50-
import org.jetbrains.kotlinx.jupyter.api.KotlinKernelHost
51-
import org.jetbrains.kotlinx.jupyter.api.Notebook
52-
import org.jetbrains.kotlinx.jupyter.api.VariableName
53-
import org.jetbrains.kotlinx.jupyter.api.declare
54-
import org.jetbrains.kotlinx.jupyter.api.libraries.ColorScheme
55-
import org.jetbrains.kotlinx.jupyter.api.libraries.JupyterIntegration
56-
import org.jetbrains.kotlinx.jupyter.api.libraries.resources
48+
import org.jetbrains.kotlinx.jupyter.api.*
49+
import org.jetbrains.kotlinx.jupyter.api.libraries.*
5750
import kotlin.reflect.KClass
5851
import kotlin.reflect.KProperty
5952
import kotlin.reflect.KType
@@ -281,16 +274,25 @@ internal class Integration(
281274
import("org.jetbrains.kotlinx.dataframe.dataTypes.*")
282275
import("org.jetbrains.kotlinx.dataframe.impl.codeGen.urlCodeGenReader")
283276

284-
updateVariable<Any> { instance, property ->
285-
when (instance) {
286-
is AnyCol -> updateAnyColVariable(instance, property, codeGen)
287-
is ColumnGroup<*> -> updateColumnGroupVariable(instance, property, codeGen)
288-
is AnyRow -> updateAnyRowVariable(instance, property, codeGen)
289-
is AnyFrame -> updateAnyFrameVariable(instance, property, codeGen)
290-
is ImportDataSchema -> updateImportDataSchemaVariable(instance, property)
291-
else -> null
277+
addTypeConverter(object : FieldHandler {
278+
override val execution = FieldHandlerFactory.createUpdateExecution<Any> { instance, property ->
279+
when (instance) {
280+
is AnyCol -> updateAnyColVariable(instance, property, codeGen)
281+
is ColumnGroup<*> -> updateColumnGroupVariable(instance, property, codeGen)
282+
is AnyRow -> updateAnyRowVariable(instance, property, codeGen)
283+
is AnyFrame -> updateAnyFrameVariable(instance, property, codeGen)
284+
is ImportDataSchema -> updateImportDataSchemaVariable(instance, property)
285+
else -> error("${instance::class} should not be handled by Dataframe field handler")
286+
}
292287
}
293-
}
288+
override fun accepts(value: Any?, property: KProperty<*>): Boolean {
289+
return value is AnyCol ||
290+
value is ColumnGroup<*> ||
291+
value is AnyRow ||
292+
value is AnyFrame ||
293+
value is ImportDataSchema
294+
}
295+
})
294296

295297
fun KotlinKernelHost.addDataSchemas(classes: List<KClass<*>>) {
296298
val code = classes.joinToString("\n") {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,19 @@ class PivotTests {
153153
1, -1, 5
154154
)
155155
}
156+
157+
@Test
158+
fun `pivot then in aggregate`() {
159+
val df = dataFrameOf(
160+
"category1" to List(12) { it % 3 },
161+
"category2" to List(12) { "category2_${it % 2}" },
162+
"category3" to List(12) { "category3_${it % 5}" },
163+
"value" to List(12) { it }
164+
)
165+
166+
val df1 = df.groupBy("category1").aggregate {
167+
pivot { "category2" then "category3" }.count()
168+
}
169+
df1 shouldBe df.pivot { "category2" then "category3" }.groupBy("category1").count()
170+
}
156171
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,23 @@ class JupyterCodegenTests : JupyterReplTestCase() {
301301
res2.shouldBeInstanceOf<Unit>()
302302
}
303303

304+
@Test
305+
fun `type converter does not conflict with other type converters`() {
306+
@Language("kts")
307+
val anotherTypeConverter = """
308+
notebook.fieldsHandlersProcessor.register(
309+
FieldHandlerFactory.createUpdateHandler<ByteArray>(TypeDetection.RUNTIME) { _, prop ->
310+
execute(prop.name + ".toList()").name
311+
},
312+
ProcessingPriority.LOW
313+
)
314+
""".trimIndent()
315+
execEx(anotherTypeConverter)
316+
execEx("val x = ByteArray(1)")
317+
val res1 = execRaw("x")
318+
res1.shouldBeInstanceOf<List<*>>()
319+
}
320+
304321
@Test
305322
fun `generate a new marker when dataframe marker is not a data schema so that columns are accessible with extensions`() {
306323
@Language("kts")

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/pivot.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public fun <G> GroupBy<*, G>.pivotCounts(vararg columns: KProperty<*>, inward: B
148148

149149
// region pivot
150150

151-
public fun <T> AggregateGroupedDsl<T>.pivot(inward: Boolean = true, columns: ColumnsSelector<T, *>): PivotGroupBy<T> =
151+
public fun <T> AggregateGroupedDsl<T>.pivot(inward: Boolean = true, columns: PivotColumnsSelector<T, *>): PivotGroupBy<T> =
152152
PivotInAggregateImpl(this, columns, inward)
153153

154154
public fun <T> AggregateGroupedDsl<T>.pivot(vararg columns: String, inward: Boolean = true): PivotGroupBy<T> =

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/shuffle.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@ package org.jetbrains.kotlinx.dataframe.api
33
import org.jetbrains.kotlinx.dataframe.DataColumn
44
import org.jetbrains.kotlinx.dataframe.DataFrame
55
import org.jetbrains.kotlinx.dataframe.indices
6+
import kotlin.random.Random
67

78
// region DataColumn
89

10+
public fun <T> DataColumn<T>.shuffle(random: Random): DataColumn<T> = get(indices.shuffled(random))
11+
912
public fun <T> DataColumn<T>.shuffle(): DataColumn<T> = get(indices.shuffled())
1013

1114
// endregion
1215

1316
// region DataFrame
1417

18+
public fun <T> DataFrame<T>.shuffle(random: Random): DataFrame<T> = getRows(indices.shuffled(random))
19+
1520
public fun <T> DataFrame<T>.shuffle(): DataFrame<T> = getRows(indices.shuffled())
1621

1722
// endregion

0 commit comments

Comments
 (0)