Skip to content

Commit dd08be6

Browse files
committed
Migrate usages of AccessOverload APIs in inline functions to public alternatives
1 parent 00b712b commit dd08be6

File tree

7 files changed

+27
-7
lines changed

7 files changed

+27
-7
lines changed

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
88
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
99
import org.jetbrains.kotlinx.dataframe.annotations.Refine
1010
import org.jetbrains.kotlinx.dataframe.columns.ColumnAccessor
11+
import org.jetbrains.kotlinx.dataframe.columns.ColumnPath
1112
import org.jetbrains.kotlinx.dataframe.impl.aggregation.internal
1213
import org.jetbrains.kotlinx.dataframe.impl.aggregation.withExpr
1314
import org.jetbrains.kotlinx.dataframe.impl.columnName
1415
import kotlin.reflect.KProperty
16+
import kotlin.reflect.KType
1517
import kotlin.reflect.typeOf
1618

1719
// region GroupBy
@@ -29,7 +31,7 @@ public fun <T> GroupBy<T, *>.into(column: KProperty<AnyFrame>): DataFrame<T> = t
2931
public inline fun <T, G, reified V> GroupBy<T, G>.into(
3032
columnName: String? = null,
3133
noinline expression: RowExpression<G, V>,
32-
): DataFrame<G> = into(pathOf(columnName ?: groups.name()).cast(), expression)
34+
): DataFrame<G> = into(pathOf(columnName ?: groups.name()), expression, typeOf<V>())
3335

3436
// @Hide
3537
@AccessApiOverload
@@ -44,6 +46,16 @@ public inline fun <T, G, reified V> GroupBy<T, G>.into(
4446
}
4547
}
4648

49+
@PublishedApi
50+
internal fun <T, G, V> GroupBy<T, G>.into(
51+
path: ColumnPath,
52+
expression: RowExpression<G, V>,
53+
type: KType,
54+
): DataFrame<G> =
55+
aggregate {
56+
internal().withExpr(type, path, expression)
57+
}
58+
4759
@AccessApiOverload
4860
public inline fun <T, G, reified V> GroupBy<T, G>.into(
4961
column: KProperty<V>,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public inline fun <reified T> Iterable<T>.toDataFrame(): DataFrame<T> =
3131
// or has no properties
3232
if (!T::class.canBeUnfolded) {
3333
// create a single `value` column
34-
ValueProperty<T>::value from { it }
34+
ValueProperty<T>::value.name from { it }
3535
} else {
3636
// otherwise creates columns based on properties
3737
properties()

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public inline fun <T, reified V> ReducedPivotGroupBy<T>.with(noinline expression
4444
val value = reducer(this)?.let {
4545
val value = expression(it, it)
4646
if (value is AnyColumnReference) {
47-
it[value]
47+
value.getValue(it)
4848
} else {
4949
value
5050
}

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/aggregations.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ internal fun <T, V> AggregateInternalDsl<T>.withExpr(type: KType, path: ColumnPa
9595
val values = df.rows().map {
9696
val value = expression(it, it)
9797
if (value is AnyColumnReference) {
98-
it[value]
98+
value.getValue(it)
9999
} else {
100100
value
101101
}

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/modes/aggregateBy.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ internal inline fun <T, reified V : R, R> Aggregator<V & Any, R>.aggregateByOrNu
112112
): DataRow<T>? =
113113
data.getOrNull(
114114
indexOfAggregationResult(
115-
values = data.asSequence().map { it[column] },
115+
values = data.asSequence().map { column.getValue(it) },
116116
valueType = typeOf<V>(),
117117
),
118118
)

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1177,8 +1177,9 @@ class DataFrameTests : BaseTest() {
11771177
.split { others }.intoRows()
11781178
.add(sum) { name.length + other().length }
11791179

1180-
val matrix = src.pivot { other }.groupBy { name }.with { sum }
1180+
val matrix = src.pivot { other }.groupBy { name }.with { sum() }
11811181
matrix.getColumnGroup(other.name()).ncol shouldBe names.size
1182+
matrix.getColumnGroup(other.name())["Alice"].type() shouldBe typeOf<List<Int>>()
11821183
}
11831184

11841185
@Test

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/PivotTests.kt

+8-1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ class PivotTests {
161161
.groupBy { name }
162162
.default("-")
163163
.values { value } shouldBe res
164+
typed
165+
.pivot { key }
166+
.groupBy { name }
167+
.default("-")
168+
.with { value() } shouldBe res
169+
170+
// special case that looks very odd, but kept it for compatibility
164171
typed
165172
.pivot { key }
166173
.groupBy { name }
@@ -180,7 +187,7 @@ class PivotTests {
180187
.pivot(key)
181188
.groupBy(name)
182189
.default("-")
183-
.with { value } shouldBe res
190+
.with { value() } shouldBe res
184191
typed
185192
.groupBy { name }
186193
.pivot { key }

0 commit comments

Comments
 (0)