Skip to content

Commit f80fd18

Browse files
committed
moved to chunkImpl
1 parent 64d1f99 commit f80fd18

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,18 @@ import org.jetbrains.kotlinx.dataframe.DataRow
66
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
77
import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
88
import org.jetbrains.kotlinx.dataframe.columns.ValueColumn
9+
import org.jetbrains.kotlinx.dataframe.impl.api.chunkedImpl
910
import org.jetbrains.kotlinx.dataframe.impl.getListType
10-
import org.jetbrains.kotlinx.dataframe.impl.splitByIndices
1111
import org.jetbrains.kotlinx.dataframe.nrow
1212
import org.jetbrains.kotlinx.dataframe.type
1313

14-
/**
15-
* Creates a [FrameColumn] from [this] by splitting the dataframe into
16-
* smaller ones, based on the given [startIndices].
17-
*/
18-
public fun <T> DataFrame<T>.chunked(startIndices: Iterable<Int>, name: String = "groups"): FrameColumn<T> =
19-
DataColumn.createFrameColumn(
20-
name = name,
21-
groups = this.splitByIndices(startIndices.asSequence()).toList(),
22-
schema = lazy { this.schema() },
23-
)
24-
2514
/**
2615
* Creates a [FrameColumn] from [this] by splitting the dataframe into
2716
* smaller ones, with their number of rows at most [size].
2817
*/
2918
public fun <T> DataFrame<T>.chunked(size: Int, name: String = "groups"): FrameColumn<T> {
3019
val startIndices = (0 until nrow step size)
31-
return this.chunked(startIndices, name)
20+
return this.chunkedImpl(startIndices, name)
3221
}
3322

3423
public fun <T> DataColumn<T>.chunked(size: Int): ValueColumn<List<T>> {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.jetbrains.kotlinx.dataframe.impl.api
2+
3+
import org.jetbrains.kotlinx.dataframe.DataColumn
4+
import org.jetbrains.kotlinx.dataframe.DataFrame
5+
import org.jetbrains.kotlinx.dataframe.api.schema
6+
import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
7+
import org.jetbrains.kotlinx.dataframe.impl.splitByIndices
8+
9+
/**
10+
* Creates a [FrameColumn] from [this] by splitting the dataframe into
11+
* smaller ones, based on the given [startIndices].
12+
*/
13+
internal fun <T> DataFrame<T>.chunkedImpl(startIndices: Iterable<Int>, name: String = "groups"): FrameColumn<T> =
14+
DataColumn.createFrameColumn(
15+
name = name,
16+
groups = this.splitByIndices(startIndices.asSequence()).toList(),
17+
schema = lazy { this.schema() },
18+
)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import org.jetbrains.kotlinx.dataframe.DataRow
66
import org.jetbrains.kotlinx.dataframe.api.GroupBy
77
import org.jetbrains.kotlinx.dataframe.api.GroupedDataRow
88
import org.jetbrains.kotlinx.dataframe.api.cast
9-
import org.jetbrains.kotlinx.dataframe.api.chunked
109
import org.jetbrains.kotlinx.dataframe.api.getColumnsWithPaths
1110
import org.jetbrains.kotlinx.dataframe.api.getRows
1211
import org.jetbrains.kotlinx.dataframe.api.indices
@@ -62,7 +61,7 @@ internal fun <T> DataFrame<T>.groupByImpl(moveToTop: Boolean, columns: ColumnsSe
6261
}
6362

6463
val groupedColumnName = keyColumnsDf.nameGenerator().addUnique(GroupBy.groupedColumnAccessor.name())
65-
val groupedColumn = sorted.chunked(startIndices.asIterable(), groupedColumnName)
64+
val groupedColumn = sorted.chunkedImpl(startIndices.asIterable(), groupedColumnName)
6665

6766
val df = keyColumnsDf + groupedColumn
6867
return GroupByImpl(df, groupedColumn, columns)

0 commit comments

Comments
 (0)