Skip to content

Commit 2535378

Browse files
committed
deprecated DataColumn.createFrameColumn with startIndices, moved it to chunked
1 parent 798edb0 commit 2535378

File tree

5 files changed

+36
-10
lines changed

5 files changed

+36
-10
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/DataColumn.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ public interface DataColumn<out T> : BaseColumn<T> {
103103
*/
104104
public fun <T> createColumnGroup(name: String, df: DataFrame<T>): ColumnGroup<T> = ColumnGroupImpl(name, df)
105105

106-
// TODO this shouldn't be here
106+
@Deprecated(
107+
message = CREATE_FRAME_COLUMN,
108+
replaceWith = ReplaceWith(CREATE_FRAME_COLUMN_REPLACE, CREATE_FRAME_COLUMN_IMPORT),
109+
level = DeprecationLevel.WARNING,
110+
)
107111
public fun <T> createFrameColumn(name: String, df: DataFrame<T>, startIndices: Iterable<Int>): FrameColumn<T> =
108112
FrameColumnImpl(name, df.splitByIndices(startIndices.asSequence()).toList(), lazy { df.schema() })
109113

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,28 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
77
import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
88
import org.jetbrains.kotlinx.dataframe.columns.ValueColumn
99
import org.jetbrains.kotlinx.dataframe.impl.getListType
10+
import org.jetbrains.kotlinx.dataframe.impl.splitByIndices
1011
import org.jetbrains.kotlinx.dataframe.nrow
1112
import org.jetbrains.kotlinx.dataframe.type
1213

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+
25+
/**
26+
* Creates a [FrameColumn] from [this] by splitting the dataframe into
27+
* smaller ones, with their number of rows at most [size].
28+
*/
1329
public fun <T> DataFrame<T>.chunked(size: Int, name: String = "groups"): FrameColumn<T> {
1430
val startIndices = (0 until nrow step size)
15-
return DataColumn.createFrameColumn(name, this, startIndices)
31+
return this.chunked(startIndices, name)
1632
}
1733

1834
public fun <T> DataColumn<T>.chunked(size: Int): ValueColumn<List<T>> {

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

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

33
import org.jetbrains.kotlinx.dataframe.ColumnsSelector
4-
import org.jetbrains.kotlinx.dataframe.DataColumn
54
import org.jetbrains.kotlinx.dataframe.DataFrame
65
import org.jetbrains.kotlinx.dataframe.DataRow
76
import org.jetbrains.kotlinx.dataframe.api.GroupBy
87
import org.jetbrains.kotlinx.dataframe.api.GroupedDataRow
98
import org.jetbrains.kotlinx.dataframe.api.cast
9+
import org.jetbrains.kotlinx.dataframe.api.chunked
1010
import org.jetbrains.kotlinx.dataframe.api.getColumnsWithPaths
1111
import org.jetbrains.kotlinx.dataframe.api.getRows
1212
import org.jetbrains.kotlinx.dataframe.api.indices
@@ -62,7 +62,7 @@ internal fun <T> DataFrame<T>.groupByImpl(moveToTop: Boolean, columns: ColumnsSe
6262
}
6363

6464
val groupedColumnName = keyColumnsDf.nameGenerator().addUnique(GroupBy.groupedColumnAccessor.name())
65-
val groupedColumn = DataColumn.createFrameColumn(groupedColumnName, sorted, startIndices.asIterable())
65+
val groupedColumn = sorted.chunked(startIndices.asIterable(), groupedColumnName)
6666

6767
val df = keyColumnsDf + groupedColumn
6868
return GroupByImpl(df, groupedColumn, columns)

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/io/readJson.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.jetbrains.kotlinx.dataframe.DataRow
2323
import org.jetbrains.kotlinx.dataframe.api.JsonPath
2424
import org.jetbrains.kotlinx.dataframe.api.KeyValueProperty
2525
import org.jetbrains.kotlinx.dataframe.api.cast
26+
import org.jetbrains.kotlinx.dataframe.api.chunked
2627
import org.jetbrains.kotlinx.dataframe.api.columnOf
2728
import org.jetbrains.kotlinx.dataframe.api.concat
2829
import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
@@ -298,11 +299,12 @@ internal fun fromJsonListAnyColumns(
298299
)
299300
}
300301

301-
else -> DataColumn.createFrameColumn(
302-
name = ARRAY_COLUMN_NAME, // will be erased
303-
df = parsed.unwrapUnnamedColumns(),
304-
startIndices = startIndices,
305-
)
302+
else ->
303+
parsed.unwrapUnnamedColumns()
304+
.chunked(
305+
startIndices = startIndices,
306+
name = ARRAY_COLUMN_NAME, // will be erased
307+
)
306308
}
307309
listOf(UnnamedColumn(res))
308310
}
@@ -640,7 +642,7 @@ internal fun fromJsonListArrayAndValueColumns(
640642
)
641643
}
642644

643-
else -> DataColumn.createFrameColumn(colName, parsed.unwrapUnnamedColumns(), startIndices)
645+
else -> parsed.unwrapUnnamedColumns().chunked(startIndices, colName)
644646
}
645647
UnnamedColumn(res)
646648
}

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/util/deprecationMessages.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ internal const val DF_READ_NO_CSV = "This function is deprecated and should be r
1515
internal const val DF_READ_NO_CSV_REPLACE =
1616
"this.readCSV(fileOrUrl, delimiter, header, colTypes, skipLines, readLines, duplicate, charset)"
1717

18+
internal const val CREATE_FRAME_COLUMN = "Replaced by df.chunked(). $MESSAGE_0_16"
19+
internal const val CREATE_FRAME_COLUMN_REPLACE = "df.chunked(startIndices, name)"
20+
internal const val CREATE_FRAME_COLUMN_IMPORT = "org.jetbrains.kotlinx.dataframe.api.chunked"
21+
1822
// endregion
1923

2024
// region WARNING in 0.16, ERROR in 0.17

0 commit comments

Comments
 (0)