Skip to content

Commit 0b22f16

Browse files
remove unneeded crossinlines
1 parent 5293bde commit 0b22f16

File tree

10 files changed

+232
-9
lines changed

10 files changed

+232
-9
lines changed

core/api/core.api

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5427,7 +5427,6 @@ public final class org/jetbrains/kotlinx/dataframe/impl/UtilsKt {
54275427
public static final fun headPlusArray (J[J)[J
54285428
public static final fun headPlusArray (S[S)[S
54295429
public static final fun headPlusArray (Z[Z)[Z
5430-
public static final fun indexOfMax (Lkotlin/sequences/Sequence;)I
54315430
public static final fun toCamelCaseByDelimiters (Ljava/lang/String;Lkotlin/text/Regex;Ljava/lang/String;)Ljava/lang/String;
54325431
public static synthetic fun toCamelCaseByDelimiters$default (Ljava/lang/String;Lkotlin/text/Regex;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
54335432
public static final fun zero (Lkotlin/reflect/KClass;)Ljava/lang/Number;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public fun <T> DataRow<T>.relative(relativeIndices: IntRange): DataFrame<T> =
205205
(relativeIndices.first + index).coerceIn(df().indices)..(relativeIndices.last + index).coerceIn(df().indices),
206206
)
207207

208-
public inline fun <T> DataRow<T>.movingAverage(k: Int, crossinline expression: RowExpression<T, Number>): Double {
208+
public inline fun <T> DataRow<T>.movingAverage(k: Int, expression: RowExpression<T, Number>): Double {
209209
var count = 0
210210
return backwardIterable().take(k).sumOf {
211211
count++

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public inline fun <T> DataFrame<T>.drop(predicate: RowFilter<T>): DataFrame<T> =
6767
/**
6868
* Returns a DataFrame containing all rows except first rows that satisfy the given [predicate].
6969
*/
70-
public inline fun <T> DataFrame<T>.dropWhile(crossinline predicate: RowFilter<T>): DataFrame<T> =
70+
public inline fun <T> DataFrame<T>.dropWhile(predicate: RowFilter<T>): DataFrame<T> =
7171
firstOrNull { !predicate(it, it) }?.let { drop(it.index()) } ?: this
7272

7373
// endregion

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public fun <T> DataFrame<T>.duplicate(n: Int): FrameColumn<T> = List(n) { this }
1111

1212
public fun <T> DataFrame<T>.duplicateRows(n: Int): DataFrame<T> = duplicateRowsImpl(n)
1313

14-
public inline fun <T> DataFrame<T>.duplicateRows(n: Int, crossinline filter: RowFilter<T>): DataFrame<T> =
14+
public inline fun <T> DataFrame<T>.duplicateRows(n: Int, filter: RowFilter<T>): DataFrame<T> =
1515
duplicateRowsImpl(n, rows().filter { filter(it, it) }.map { it.index() })
1616

1717
public fun <T> DataRow<T>.duplicate(n: Int): DataFrame<T> = duplicateImpl(n)

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

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,102 @@ import org.jetbrains.kotlinx.dataframe.DataFrame
77
import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
88
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
99
import org.jetbrains.kotlinx.dataframe.annotations.Refine
10+
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
1011
import org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath
1112
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
13+
import org.jetbrains.kotlinx.dataframe.documentation.DocumentationUrls
14+
import org.jetbrains.kotlinx.dataframe.documentation.DslGrammarLink
15+
import org.jetbrains.kotlinx.dataframe.documentation.ExcludeFromSources
16+
import org.jetbrains.kotlinx.dataframe.documentation.Indent
17+
import org.jetbrains.kotlinx.dataframe.documentation.LineBreak
18+
import org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns
1219
import org.jetbrains.kotlinx.dataframe.impl.columnName
1320
import kotlin.experimental.ExperimentalTypeInference
1421
import kotlin.reflect.KProperty
1522

1623
// region DataFrame
1724

25+
/**
26+
* Groups the specified [columns\] within the [DataFrame].
27+
*
28+
* This function does not immediately group the columns but instead select columns to group and
29+
* returns a [GroupClause],
30+
* which serves as an intermediate step.
31+
* The [GroupClause] allows specifying the final
32+
* destination of the selected columns using methods such
33+
* as [into][GroupClause.into] and,
34+
* that return a new [DataFrame] with grouped columns.
35+
* Check out [Grammar].
36+
*
37+
* @include [SelectingColumns.ColumnGroupsAndNestedColumnsMention]
38+
*
39+
* See [Selecting Columns][GroupSelectingOptions].
40+
*
41+
* For more information: {@include [DocumentationUrls.Group]}
42+
*
43+
* Reverse operation: [ungroup].
44+
*
45+
* It is a special case of [move] operation.
46+
*
47+
* Don't confuse this with [groupBy],
48+
* which groups the dataframe by the values in the selected columns!
49+
*/
50+
internal interface GroupDocs {
51+
52+
/**
53+
* {@comment Version of [SelectingColumns] with correctly filled in examples}
54+
* @include [SelectingColumns] {@include [SetGroupOperationArg]}
55+
*/
56+
interface GroupSelectingOptions
57+
58+
/**
59+
* ## Group Operation Grammar
60+
* {@include [LineBreak]}
61+
* {@include [DslGrammarLink]}
62+
* {@include [LineBreak]}
63+
*
64+
* [**`into`**][GroupClause.into]**`(`**`groupName: `[`String`][String]**`)`**
65+
*
66+
* {@include [Indent]}
67+
* __`.`__[**`into`**][GroupClause.into]**` { `**`groupNameExpression: `[`ColumnsSelector`][ColumnsSelector]**` } `**
68+
*/
69+
interface Grammar
70+
}
71+
72+
/** {@set [SelectingColumns.OPERATION] [group][group]} */
73+
@ExcludeFromSources
74+
private interface SetGroupOperationArg
75+
76+
/**
77+
* {@include [GroupDocs]}
78+
* ### This Group Overload
79+
*/
80+
@ExcludeFromSources
81+
private interface CommonGroupDocs
82+
83+
/**
84+
* @include [CommonGroupDocs]
85+
* @include [SelectingColumns.Dsl] {@include [SetGroupOperationArg]}
86+
* ### Examples:
87+
* ```kotlin
88+
* df.group { columnA and columnB }.into("valueCols")
89+
* df.group { colsOf<String>() }.into { it.name.split(".").first() }
90+
* ```
91+
* @param [columns\] The [Columns Selector][ColumnsSelector] used to select the columns of this [DataFrame] to group.
92+
*/
1893
@Interpretable("Group0")
1994
public fun <T, C> DataFrame<T>.group(columns: ColumnsSelector<T, C>): GroupClause<T, C> = GroupClause(this, columns)
2095

96+
/**
97+
* @include [CommonGroupDocs]
98+
* @include [SelectingColumns.ColumnNames] {@include [SetGroupOperationArg]}
99+
* ### Example:
100+
* ```kotlin
101+
* df.group("second").into("valueCols")
102+
* df.group("prop.A", "prop.B", "cnt.A", "cnt.B").into { it.name.split(".").first() }
103+
* ```
104+
* @param [columns\] The [Column Names][String] used to select the columns of this [DataFrame] to group.
105+
*/
21106
public fun <T> DataFrame<T>.group(vararg columns: String): GroupClause<T, Any?> = group { columns.toColumnSet() }
22107

23108
@AccessApiOverload
@@ -31,23 +116,110 @@ public fun <T> DataFrame<T>.group(vararg columns: KProperty<*>): GroupClause<T,
31116

32117
// region GroupClause
33118

119+
/**
120+
* An intermediate class used in the [group] operation.
121+
*
122+
* This class itself does nothing—it is just a transitional step before specifying
123+
* how to group the selected columns.
124+
* It must be followed by one of the positioning methods
125+
* to produce a new [DataFrame] with the updated column structure.
126+
*
127+
* Use the following methods to finalize the move:
128+
* - [into(groupName)][GroupClause.into] – groups selected columns into a one column group.
129+
* - [into { groupNameExpression }][GroupClause.into] – groups each column into a group
130+
* by specifying path or name.
131+
*
132+
* See [Grammar][GroupDocs.Grammar] for more details.
133+
*/
34134
public class GroupClause<T, C>(internal val df: DataFrame<T>, internal val columns: ColumnsSelector<T, C>) {
35135
override fun toString(): String = "GroupClause(df=$df, columns=$columns)"
36136
}
37137

38138
// region into
39139

140+
/**
141+
* Groups columns, previously selected with [group], into new or existing column groups
142+
* within the [DataFrame], using an [ColumnsSelectionDsl] expression to specify the target group name for each column.
143+
* The expression is applied to each selected column and determines the name of the column group
144+
* it will be placed into.
145+
*
146+
* If a column group with the specified name does not exist, it will be created.
147+
*
148+
* See [Selecting Columns][SelectingColumns].
149+
*
150+
* For more information: {@include [DocumentationUrls.Group]}
151+
*
152+
* @include [SelectingColumns.ColumnNames]
153+
*
154+
* ### Example:
155+
* ```kotlin
156+
* df.group { all() }.into { it.type().toString() }
157+
* ```
158+
*
159+
* @param column A [ColumnsSelector] expression that takes a column and returns the name of the [ColumnGroup]
160+
* where that column should be grouped.
161+
* All selected columns will be moved under the groups defined by this expression.
162+
*/
40163
@JvmName("intoString")
41164
@OverloadResolutionByLambdaReturnType
42165
@OptIn(ExperimentalTypeInference::class)
43166
public fun <T, C> GroupClause<T, C>.into(column: ColumnsSelectionDsl<T>.(ColumnWithPath<C>) -> String): DataFrame<T> =
44167
df.move(columns).under { column(it).toColumnAccessor() }
45168

169+
/**
170+
* Groups columns, previously selected with [group], into a new or existing column group
171+
* within the [DataFrame] by specifying its path via [ColumnsSelectionDsl] expression.
172+
*
173+
* If the specified path refers to a non-existent column group, it will be created automatically,
174+
* including any missing intermediate segments.
175+
*
176+
* See [Selecting Columns][SelectingColumns].
177+
*
178+
* For more information: {@include [DocumentationUrls.Group]}
179+
*
180+
* @include [SelectingColumns.ColumnNames]
181+
*
182+
* ### Examples:
183+
* ```kotlin
184+
* // Group selected columns into an existing column group:
185+
* df.group("age", "weight").into { info }
186+
* // Group selected columns into a nested column group using a path that may
187+
* // contain both existing and new segments:
188+
* df.group { employee.age and employee.weight }.into { pathOf("info", "personal") }
189+
* // Group selected columns under their ancestor group located two levels up in the path hierarchy
190+
* df.group { colsAtAnyDepth().colsOf<String>() }.into { it.path.dropLast(2) }
191+
* ```
192+
*
193+
* @param column A [ColumnsSelector] expression that takes a column and returns the full path to the [ColumnGroup]
194+
* where that column should be grouped.
195+
* All selected columns will be moved under the groups defined by this expression.
196+
*/
46197
@JvmName("intoColumn")
47198
public fun <T, C> GroupClause<T, C>.into(
48199
column: ColumnsSelectionDsl<T>.(ColumnWithPath<C>) -> AnyColumnReference,
49200
): DataFrame<T> = df.move(columns).under(column)
50201

202+
/**
203+
* Groups columns, previously selected with [group], into a new or existing column group
204+
* within the [DataFrame], by specifying its name.
205+
*
206+
* If a column group with the specified name does not exist, it will be created.
207+
*
208+
* See [Selecting Columns][SelectingColumns].
209+
*
210+
* For more information: {@include [DocumentationUrls.Group]}
211+
*
212+
* @include [SelectingColumns.ColumnNames]
213+
*
214+
* ### Examples:
215+
* ```kotlin
216+
* df.group("age", "weight").into("info")
217+
* df.group { age and weight }.into("info")
218+
* ```
219+
*
220+
* @param [column] A [ColumnsSelector] that defines the path to a [ColumnGroup]
221+
* in the [DataFrame], where the selected columns will be moved.
222+
*/
51223
@Refine
52224
@Interpretable("Into0")
53225
public fun <T, C> GroupClause<T, C>.into(column: String): DataFrame<T> = into(columnGroup().named(column))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public fun <T> DataFrame<T>.takeLast(n: Int = 1): DataFrame<T> {
6060
/**
6161
* Returns a DataFrame containing first rows that satisfy the given [predicate].
6262
*/
63-
public inline fun <T> DataFrame<T>.takeWhile(crossinline predicate: RowFilter<T>): DataFrame<T> =
63+
public inline fun <T> DataFrame<T>.takeWhile(predicate: RowFilter<T>): DataFrame<T> =
6464
firstOrNull { !predicate(it, it) }?.let { take(it.index()) } ?: this
6565

6666
// endregion

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,65 @@ import org.jetbrains.kotlinx.dataframe.DataFrame
66
import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
77
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
88
import org.jetbrains.kotlinx.dataframe.annotations.Refine
9+
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
910
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
11+
import org.jetbrains.kotlinx.dataframe.documentation.DocumentationUrls
12+
import org.jetbrains.kotlinx.dataframe.documentation.ExcludeFromSources
13+
import org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns
1014
import org.jetbrains.kotlinx.dataframe.impl.columns.toColumnSet
1115
import org.jetbrains.kotlinx.dataframe.impl.removeAt
1216
import kotlin.reflect.KProperty
1317

1418
// region DataFrame
1519

20+
/**
21+
* Ungroups the specified [column groups][columns\] within the [DataFrame], i.e.,
22+
* replaces each [ColumnGroup] with its nested columns.
23+
*
24+
* See [Selecting Columns][UngroupSelectingOptions].
25+
*
26+
* For more information: {@include [DocumentationUrls.Ungroup]}
27+
*/
28+
internal interface UngroupDocs {
29+
/**
30+
* {@comment Version of [SelectingColumns] with correctly filled in examples}
31+
* @include [SelectingColumns] {@include [SetUngroupOperationArg]}
32+
*/
33+
interface UngroupSelectingOptions
34+
}
35+
36+
/** {@set [SelectingColumns.OPERATION] [ungroup][ungroup]} */
37+
@ExcludeFromSources
38+
private interface SetUngroupOperationArg
39+
40+
/**
41+
* {@include [UngroupDocs]}
42+
* ### This Ungroup Overload
43+
*/
44+
@ExcludeFromSources
45+
private interface CommonUngroupDocs
46+
47+
/**
48+
* @include [CommonUngroupDocs]
49+
* @include [SelectingColumns.Dsl] {@include [SetUngroupOperationArg]}
50+
* ### Examples:
51+
* ```kotlin
52+
* df.ungroup { groupA and groupB }
53+
* df.ungroup { all() }
54+
* ```
55+
* @param [columns\] The [Columns Selector][ColumnsSelector] used to select the column groups of this [DataFrame] to ungroup.
56+
*/
1657
@Refine
1758
@Interpretable("Ungroup0")
1859
public fun <T, C> DataFrame<T>.ungroup(columns: ColumnsSelector<T, C>): DataFrame<T> =
1960
move { columns.toColumnSet().colsInGroups() }
2061
.into { it.path.removeAt(it.path.size - 2).toPath() }
2162

63+
/**
64+
* @include [CommonUngroupDocs]
65+
* @include [SelectingColumns.ColumnNames.WithExample] {@include [SetUngroupOperationArg]}
66+
* @param [columns\] The [Column Names][String] used to select the columns of this [DataFrame] to ungroup.
67+
*/
2268
public fun <T> DataFrame<T>.ungroup(vararg columns: String): DataFrame<T> = ungroup { columns.toColumnSet() }
2369

2470
@AccessApiOverload

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/DocumentationUrls.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,10 @@ internal interface DocumentationUrls {
9292

9393
/** [See `move` on the documentation website.]({@include [Url]}/move.html) */
9494
interface Move
95+
96+
/** [See `group` on the documentation website.]({@include [Url]}/group.html) */
97+
interface Group
98+
99+
/** [See `group` on the documentation website.]({@include [Url]}/ungroup.html) */
100+
interface Ungroup
95101
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ private fun DataColumn<Any?>.convertToComparableOrNull(): DataColumn<Comparable<
118118

119119
// Found incomparable number types, convert all to Double first
120120
isNumber() -> with(cast<Number?>()) {
121-
if (any { it?.isPrimitiveNumber() == false }) {
122-
return@convertToComparableOrNull null
121+
map {
122+
if (it?.isPrimitiveNumber() == false) return@convertToComparableOrNull null
123+
it?.toDouble() as Comparable<Any>?
123124
}
124-
map { it?.toDouble() as Comparable<Any>? }
125125
}
126126

127127
else -> null

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal class JoinedDataRowImpl<A, B>(
2525
override val right: DataRow<B> = DataRowImpl(index1, rightOwner)
2626
}
2727

28-
internal inline fun <A, B> DataFrame<A>.joinWithImpl(
28+
internal fun <A, B> DataFrame<A>.joinWithImpl(
2929
right: DataFrame<B>,
3030
type: JoinType = JoinType.Inner,
3131
addNewColumns: Boolean,

0 commit comments

Comments
 (0)