Skip to content

Commit a29bc38

Browse files
Automated commit of generated code
1 parent ab70055 commit a29bc38

File tree

6 files changed

+81
-13
lines changed

6 files changed

+81
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ public class DataFrameBuilder(private val header: List<String>) {
393393

394394
@JvmName("invoke1")
395395
internal fun withValues(values: Iterable<Any?>): DataFrame<*> =
396-
withValuesImpl(header, values.asList()).map { (name, values) ->
396+
(header to values.asList()).withValuesImpl().map { (name, values) ->
397397
DataColumn.createByInference(name, values)
398398
}.toDataFrame()
399399

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

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import org.jetbrains.kotlinx.dataframe.ColumnsSelector
44
import org.jetbrains.kotlinx.dataframe.DataFrame
55
import org.jetbrains.kotlinx.dataframe.RowValueFilter
66
import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
7+
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
8+
import org.jetbrains.kotlinx.dataframe.annotations.Refine
79
import org.jetbrains.kotlinx.dataframe.columns.ColumnAccessor
810
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
911
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
@@ -15,6 +17,7 @@ import kotlin.reflect.typeOf
1517

1618
// region gather
1719

20+
@Interpretable("Gather0")
1821
public fun <T, C> DataFrame<T>.gather(selector: ColumnsSelector<T, C>): Gather<T, C, String, C> =
1922
Gather(
2023
df = this,
@@ -44,30 +47,76 @@ public fun <T, C> DataFrame<T>.gather(vararg columns: KProperty<C>): Gather<T, C
4447

4548
// endregion
4649

50+
@Interpretable("GatherWhere")
4751
public fun <T, C, K, R> Gather<T, C, K, R>.where(filter: RowValueFilter<T, C>): Gather<T, C, K, R> =
48-
copy(filter = this.filter and filter)
52+
Gather(
53+
df = df,
54+
columns = columns,
55+
filter = this.filter and filter,
56+
keyType = keyType,
57+
keyTransform = keyTransform,
58+
valueTransform = valueTransform,
59+
explode = explode,
60+
)
4961

62+
@Interpretable("GatherChangeType")
5063
public fun <T, C, K, R> Gather<T, C?, K, R>.notNull(): Gather<T, C, K, R> = where { it != null } as Gather<T, C, K, R>
5164

52-
public fun <T, C, K, R> Gather<T, C, K, R>.explodeLists(): Gather<T, C, K, R> = copy(explode = true)
65+
@Interpretable("GatherExplodeLists")
66+
public fun <T, C, K, R> Gather<T, C, K, R>.explodeLists(): Gather<T, C, K, R> =
67+
Gather(
68+
df = df,
69+
columns = columns,
70+
filter = filter,
71+
keyType = keyType,
72+
keyTransform = keyTransform,
73+
valueTransform = valueTransform,
74+
explode = true,
75+
)
5376

77+
@Interpretable("GatherMap")
5478
public inline fun <T, C, reified K, R> Gather<T, C, *, R>.mapKeys(
5579
noinline transform: (String) -> K,
5680
): Gather<T, C, K, R> =
57-
copy(keyTransform = transform as ((String) -> Nothing), keyType = typeOf<K>()) as Gather<T, C, K, R>
81+
Gather(
82+
df = df,
83+
columns = columns,
84+
filter = filter,
85+
keyType = typeOf<K>(),
86+
keyTransform = transform,
87+
valueTransform = valueTransform,
88+
explode = explode,
89+
)
5890

91+
@Interpretable("GatherMap")
5992
public fun <T, C, K, R> Gather<T, C, K, *>.mapValues(transform: (C) -> R): Gather<T, C, K, R> =
60-
copy(valueTransform = transform as ((C) -> Nothing)) as Gather<T, C, K, R>
93+
Gather(
94+
df = df,
95+
columns = columns,
96+
filter = filter,
97+
keyType = keyType,
98+
keyTransform = keyTransform,
99+
valueTransform = transform,
100+
explode = explode,
101+
)
61102

62-
public data class Gather<T, C, K, R>(
103+
public class Gather<T, C, K, R>(
104+
@PublishedApi
63105
internal val df: DataFrame<T>,
106+
@PublishedApi
64107
internal val columns: ColumnsSelector<T, C>,
108+
@PublishedApi
65109
internal val filter: RowValueFilter<T, C>? = null,
110+
@PublishedApi
66111
internal val keyType: KType? = null,
112+
@PublishedApi
67113
internal val keyTransform: ((String) -> K),
114+
@PublishedApi
68115
internal val valueTransform: ((C) -> R)? = null,
116+
@PublishedApi
69117
internal val explode: Boolean = false,
70118
) {
119+
@Interpretable("GatherChangeType")
71120
public fun <P> cast(): Gather<T, P, K, P> {
72121
// TODO: introduce GatherWithTransform to avoid this error
73122
require(valueTransform == null) { "Cast is not allowed to be called after `mapValues`" }
@@ -77,6 +126,8 @@ public data class Gather<T, C, K, R>(
77126

78127
// region into
79128

129+
@Refine
130+
@Interpretable("GatherInto")
80131
public fun <T, C, K, R> Gather<T, C, K, R>.into(keyColumn: String, valueColumn: String): DataFrame<T> =
81132
gatherImpl(keyColumn, valueColumn)
82133

@@ -100,6 +151,8 @@ public fun <T, C, K, R> Gather<T, C, K, R>.into(keyColumn: KProperty<K>, valueCo
100151

101152
// region keysInto
102153

154+
@Refine
155+
@Interpretable("GatherKeysInto")
103156
public fun <T, C, K, R> Gather<T, C, K, R>.keysInto(keyColumn: String): DataFrame<T> = gatherImpl(keyColumn, null)
104157

105158
@Deprecated(
@@ -120,6 +173,8 @@ public fun <T, C, K, R> Gather<T, C, K, R>.keysInto(keyColumn: KProperty<K>): Da
120173

121174
// region valuesInto
122175

176+
@Refine
177+
@Interpretable("GatherValuesInto")
123178
public fun <T, C, K, R> Gather<T, C, K, R>.valuesInto(valueColumn: String): DataFrame<T> = gatherImpl(null, valueColumn)
124179

125180
@Deprecated(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ package org.jetbrains.kotlinx.dataframe.exceptions
22

33
public class ColumnNotFoundException(public val columnName: String, public override val message: String) :
44
RuntimeException(),
5-
DataFrameException
5+
DataFrameError
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package org.jetbrains.kotlinx.dataframe.exceptions
22

33
/**
4-
* If DataFrame function used by compiler plugin as implementation detail throws this exception, [message] will be reported as warning
4+
* If DataFrame function used by compiler plugin as implementation detail throws exception
5+
* that implements this interface, [message] will be reported as warning
56
*/
6-
public interface DataFrameException {
7+
public interface DataFrameError {
78
public val message: String
89
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package org.jetbrains.kotlinx.dataframe.exceptions
22

33
public class DuplicateColumnNamesException(public val allColumnNames: List<String>) :
44
IllegalArgumentException(),
5-
DataFrameException {
5+
DataFrameError {
66

77
public val duplicatedNames: List<String> = allColumnNames
88
.groupBy { it }

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
package org.jetbrains.kotlinx.dataframe.impl.api
22

3-
internal fun <T> withValuesImpl(header: List<String>, values: List<T>): List<Pair<String, List<T>>> {
3+
import org.jetbrains.kotlinx.dataframe.exceptions.DataFrameError
4+
5+
/**
6+
* Public API to be re-used in compiler plugin implementation
7+
*/
8+
public fun <T> Pair<List<String>, List<T>>.withValuesImpl(): List<Pair<String, List<T>>> {
9+
val (header, values) = this
410
val ncol = header.size
511

6-
require(header.isNotEmpty() && values.size.rem(ncol) == 0) {
7-
"Number of values ${values.size} is not divisible by number of columns $ncol"
12+
if (!(header.isNotEmpty() && values.size.rem(ncol) == 0)) {
13+
throw WrongNumberOfValuesException(values.size, ncol)
814
}
915

1016
val nrow = values.size / ncol
@@ -16,3 +22,9 @@ internal fun <T> withValuesImpl(header: List<String>, values: List<T>): List<Pai
1622
header[col] to colValues
1723
}
1824
}
25+
26+
internal class WrongNumberOfValuesException(size: Int, ncol: Int) :
27+
IllegalArgumentException(),
28+
DataFrameError {
29+
override val message = "Number of values $size is not divisible by number of columns $ncol"
30+
}

0 commit comments

Comments
 (0)