Skip to content

Commit 25d4821

Browse files
committed
seems to be working! In the process of converting dfs usage to recursively/rec
1 parent 8fffbd1 commit 25d4821

File tree

51 files changed

+305
-385
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+305
-385
lines changed

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,6 @@ public interface DataColumn<out T> : BaseColumn<T> {
107107

108108
override fun resolveSingle(context: ColumnResolutionContext): ColumnWithPath<T>? = this.addPath()
109109

110-
override fun resolveSingleAfterTransform(
111-
context: ColumnResolutionContext,
112-
transformer: ColumnSetTransformer,
113-
): ColumnWithPath<T>? =
114-
transformer.transformRemainingSingle(this).cast<T>()
115-
.let { it as DataColumn<T> }
116-
.addPath()
117-
118110
override operator fun getValue(thisRef: Any?, property: KProperty<*>): DataColumn<T> =
119111
super.getValue(thisRef, property) as DataColumn<T>
120112

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -734,9 +734,8 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
734734
override fun resolveAfterTransform(
735735
context: ColumnResolutionContext,
736736
transformer: ColumnSetTransformer,
737-
): List<ColumnWithPath<Any?>> =
738-
process(transformer.transformRemainingSingle(this@rangeTo) as AnyColumnReference, context)
739-
}
737+
): List<ColumnWithPath<Any?>> = throw UnsupportedOperationException("Not implemented")
738+
}.wrap()
740739

741740
/**
742741
* ## None
@@ -3908,21 +3907,21 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
39083907

39093908
@Deprecated(
39103909
message = "dfs is deprecated, use recursively instead.",
3911-
replaceWith = ReplaceWith("this.cols(predicate).recursively(includeTopLevel = false)"),
3910+
replaceWith = ReplaceWith("this.cols(predicate).recursively(includeTopLevel = true)"),
39123911
level = DeprecationLevel.WARNING,
39133912
)
39143913
public fun <C> ColumnSet<C>.dfs(predicate: (ColumnWithPath<*>) -> Boolean): ColumnSet<Any?> = dfsInternal(predicate)
39153914

39163915
@Deprecated(
39173916
message = "dfs is deprecated, use recursively instead.",
3918-
replaceWith = ReplaceWith("this.cols(predicate).recursively(includeTopLevel = false)"),
3917+
replaceWith = ReplaceWith("this.cols(predicate).recursively(includeTopLevel = true)"),
39193918
level = DeprecationLevel.WARNING,
39203919
)
39213920
public fun String.dfs(predicate: (ColumnWithPath<*>) -> Boolean): ColumnSet<*> = toColumnAccessor().dfs(predicate)
39223921

39233922
@Deprecated(
39243923
message = "dfs is deprecated, use recursively instead.",
3925-
replaceWith = ReplaceWith("this.cols(predicate).recursively(includeTopLevel = false)"),
3924+
replaceWith = ReplaceWith("this.cols(predicate).recursively(includeTopLevel = true)"),
39263925
level = DeprecationLevel.WARNING,
39273926
)
39283927
public fun <C> KProperty<C>.dfs(predicate: (ColumnWithPath<*>) -> Boolean): ColumnSet<*> =
@@ -3933,7 +3932,7 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
39333932
// region all
39343933
public fun ColumnSet<*>.all(): ColumnSet<*> = wrap()
39353934

3936-
public fun SingleColumn<*>.all(): ColumnSet<*> = transformSingle { it.children() }.wrap()
3935+
public fun SingleColumn<*>.all(): ColumnSet<*> = transformSingle { it.children() }
39373936

39383937
public fun String.all(): ColumnSet<*> = toColumnAccessor().all()
39393938

@@ -3943,22 +3942,22 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
39433942

39443943
@Deprecated(
39453944
message = "allDfs is deprecated, use recursively instead.",
3946-
replaceWith = ReplaceWith("this.allRecursively(includeGroups = includeGroups, includeTopLevel = false)"),
3945+
replaceWith = ReplaceWith("this.all().recursively(includeGroups = includeGroups)"),
39473946
level = DeprecationLevel.WARNING,
39483947
)
39493948
public fun ColumnSet<*>.allDfs(includeGroups: Boolean = false): ColumnSet<Any?> =
39503949
if (includeGroups) dfs { true } else dfs { !it.isColumnGroup() }
39513950

39523951
@Deprecated(
39533952
message = "allDfs is deprecated, use recursively instead.",
3954-
replaceWith = ReplaceWith("this.allRecursively(includeGroups = includeGroups, includeTopLevel = false)"),
3953+
replaceWith = ReplaceWith("this.all().recursively(includeGroups = includeGroups)"),
39553954
level = DeprecationLevel.WARNING,
39563955
)
39573956
public fun String.allDfs(includeGroups: Boolean = false): ColumnSet<Any?> = toColumnAccessor().allDfs(includeGroups)
39583957

39593958
@Deprecated(
39603959
message = "allDfs is deprecated, use recursively instead.",
3961-
replaceWith = ReplaceWith("this.allRecursively(includeGroups = includeGroups, includeTopLevel = false)"),
3960+
replaceWith = ReplaceWith("this.all().recursively(includeGroups = includeGroups)"),
39623961
level = DeprecationLevel.WARNING,
39633962
)
39643963
public fun KProperty<*>.allDfs(includeGroups: Boolean = false): ColumnSet<Any?> =
@@ -4000,25 +3999,26 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
40003999
includeTopLevel: Boolean = true,
40014000
): ColumnSet<*> = recursively(includeTopLevel = includeTopLevel, includeGroups = includeGroups)
40024001

4003-
public fun <C> ColumnSet<C>.allRecursively(
4002+
public fun String.recursively(
40044003
includeGroups: Boolean = true,
40054004
includeTopLevel: Boolean = true,
4006-
): ColumnSet<C> = wrap().recursivelyImpl(includeTopLevel = includeTopLevel, includeGroups = includeGroups)
4005+
): ColumnSet<*> = toColumnAccessor().recursively(includeGroups, includeTopLevel)
40074006

4008-
public fun <C> ColumnSet<C>.allRec(
4007+
public fun String.rec(
40094008
includeGroups: Boolean = true,
40104009
includeTopLevel: Boolean = true,
4011-
): ColumnSet<C> = allRecursively(includeTopLevel = includeTopLevel, includeGroups = includeGroups)
4010+
): ColumnSet<*> = recursively(includeTopLevel = includeTopLevel, includeGroups = includeGroups)
40124011

4013-
public fun SingleColumn<*>.allRecursively(
4012+
public fun KProperty<*>.recursively(
40144013
includeGroups: Boolean = true,
40154014
includeTopLevel: Boolean = true,
4016-
): ColumnSet<*> = all().recursivelyImpl(includeTopLevel = includeTopLevel, includeGroups = includeGroups)
4015+
): ColumnSet<*> = toColumnAccessor().recursively(includeGroups, includeTopLevel)
40174016

4018-
public fun SingleColumn<*>.allRec(
4017+
public fun KProperty<*>.rec(
40194018
includeGroups: Boolean = true,
40204019
includeTopLevel: Boolean = true,
4021-
): ColumnSet<*> = allRecursively(includeTopLevel = includeTopLevel, includeGroups = includeGroups)
4020+
): ColumnSet<*> = recursively(includeTopLevel = includeTopLevel, includeGroups = includeGroups)
4021+
40224022

40234023
// endregion
40244024

@@ -4431,7 +4431,7 @@ internal fun <T, C> ColumnsSelector<T, C>.filter(predicate: (ColumnWithPath<C>)
44314431
*/
44324432
internal fun ColumnSet<*>.colsInternal(predicate: ColumnFilter<*>): ColumnSet<*> =
44334433
transform {
4434-
if (this is SingleColumn<*> && it.singleOrNull()?.isColumnGroup() == true) {
4434+
if (isSingleColumn() && it.singleOrNull()?.isColumnGroup() == true) {
44354435
it.single().children()
44364436
} else {
44374437
it

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public data class Corr<T, C>(
1818
internal val columns: ColumnsSelector<T, C>,
1919
)
2020

21-
public fun <T> DataFrame<T>.corr(): DataFrame<T> = corr { dfs { it.isSuitableForCorr() } }.withItself()
21+
public fun <T> DataFrame<T>.corr(): DataFrame<T> = corr { cols { it.isSuitableForCorr() }.rec() }.withItself()
2222

2323
public fun <T, C> DataFrame<T>.corr(columns: ColumnsSelector<T, C>): Corr<T, C> = Corr(this, columns)
2424
public fun <T> DataFrame<T>.corr(vararg columns: String): Corr<T, Any?> = corr { columns.toColumnSet() }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
1010
import org.jetbrains.kotlinx.dataframe.impl.api.explodeImpl
1111
import kotlin.reflect.KProperty
1212

13-
private val defaultExplodeColumns: ColumnsSelector<*, *> = { dfs { it.isList() || it.isFrameColumn() } }
13+
private val defaultExplodeColumns: ColumnsSelector<*, *> = { cols { it.isList() || it.isFrameColumn() }.rec() }
1414

1515
// region explode DataFrame
1616

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,16 @@ public fun <T, C> DataFrame<T>.rename(cols: Iterable<ColumnReference<C>>): Renam
4040

4141
public data class RenameClause<T, C>(val df: DataFrame<T>, val columns: ColumnsSelector<T, C>)
4242

43-
public fun <T> DataFrame<T>.renameToCamelCase(): DataFrame<T> {
44-
return rename {
45-
dfs { it.isColumnGroup() && it.name() matches DELIMITED_STRING_REGEX }
43+
public fun <T> DataFrame<T>.renameToCamelCase(): DataFrame<T> = this
44+
.rename {
45+
cols { it.isColumnGroup() && it.name() matches DELIMITED_STRING_REGEX }.rec()
4646
}.toCamelCase()
47-
.rename {
48-
dfs { !it.isColumnGroup() && it.name() matches DELIMITED_STRING_REGEX }
49-
}.toCamelCase()
50-
.update {
51-
dfsOf<AnyFrame>()
52-
}.with { it.renameToCamelCase() }
53-
}
47+
.rename {
48+
cols { !it.isColumnGroup() && it.name() matches DELIMITED_STRING_REGEX }.rec()
49+
}.toCamelCase()
50+
.update {
51+
colsOf<AnyFrame>().rec()
52+
}.with { it.renameToCamelCase() }
5453

5554
public fun <T, C> RenameClause<T, C>.into(vararg newColumns: ColumnReference<*>): DataFrame<T> =
5655
into(*newColumns.map { it.name() }.toTypedArray())
@@ -59,6 +58,7 @@ public fun <T, C> RenameClause<T, C>.into(vararg newNames: String): DataFrame<T>
5958
df.move(columns).intoIndexed { col, index ->
6059
col.path.dropLast(1) + newNames[index]
6160
}
61+
6262
public fun <T, C> RenameClause<T, C>.into(vararg newNames: KProperty<*>): DataFrame<T> =
6363
into(*newNames.map { it.name }.toTypedArray())
6464

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/columns/ColumnReference.kt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,6 @@ public interface ColumnReference<out C> : SingleColumn<C> {
3636
context.df
3737
.getColumn<C>(path(), context.unresolvedColumnsPolicy)
3838
?.addPath(path())
39-
40-
override fun resolveSingleAfterTransform(
41-
context: ColumnResolutionContext,
42-
transformer: ColumnSetTransformer,
43-
): ColumnWithPath<C>? =
44-
transformer.transformRemainingSingle(context.df.asColumnGroup()).cast<C>()
45-
.resolve(context)
46-
.toDataFrame()
47-
.getColumn<C>(path(), context.unresolvedColumnsPolicy)
48-
?.addPath(path())
4939
}
5040

5141
internal fun <C> ColumnReference<C>.renamedReference(newName: String): ColumnReference<C> =

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/columns/ColumnSet.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ public interface ColumnSet<out C> {
3232

3333
public interface ColumnSetTransformer {
3434

35-
public fun transformRemainingSingle(singleColumn: SingleColumn<*>): SingleColumn<*>
35+
// @Deprecated("see if this can be removed")
36+
// public fun transformRemainingSingle(singleColumn: SingleColumn<*>): SingleColumn<*>
3637

37-
public fun transformSingle(singleColumn: SingleColumn<*>): ColumnSet<*>
38+
// public fun transformSingle(singleColumn: SingleColumn<*>): ColumnSet<*>
3839

3940
public fun transform(columnSet: ColumnSet<*>): ColumnSet<*>
4041
}

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/columns/SingleColumn.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ public interface SingleColumn<out C> : ColumnSet<C> {
1616
override fun resolveAfterTransform(
1717
context: ColumnResolutionContext,
1818
transformer: ColumnSetTransformer,
19-
): List<ColumnWithPath<C>> = resolveSingleAfterTransform(context, transformer)?.let { listOf(it) } ?: emptyList()
19+
): List<ColumnWithPath<C>> =
20+
throw UnsupportedOperationException(
21+
"SingleColumn.resolveAfterTransform is not supported because transformations can only be applied on normal ColumnSets. use '.wrap()' to wrap a SingleColumn into a ColumnSet"
22+
)
2023

2124
public fun resolveSingle(context: ColumnResolutionContext): ColumnWithPath<C>?
22-
23-
public fun resolveSingleAfterTransform(
24-
context: ColumnResolutionContext,
25-
transformer: ColumnSetTransformer,
26-
): ColumnWithPath<C>?
2725
}
26+
27+
public fun ColumnSet<*>.isSingleColumn(): Boolean = this is SingleColumn<*>

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,6 @@ internal open class DataFrameReceiver<T>(
5555
override fun resolveSingle(context: ColumnResolutionContext): ColumnWithPath<DataRow<T>>? =
5656
DataColumn.createColumnGroup("", df).addPath(emptyPath())
5757

58-
override fun resolveSingleAfterTransform(
59-
context: ColumnResolutionContext,
60-
transformer: ColumnSetTransformer,
61-
): ColumnWithPath<DataRow<T>>? =
62-
DataColumn.createColumnGroup(
63-
name = "",
64-
df = createColumnSet { df.columns().map { it.addPath() } }
65-
.let(transformer::transform).cast<T>()
66-
.resolve(context)
67-
.toDataFrame() as DataFrame<T>,
68-
).addPath(emptyPath())
69-
7058
override fun columns() =
7159
df.columns().map { if (it.isColumnGroup()) ColumnGroupWithParent(null, it.asColumnGroup()) else it }
7260

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

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

33
import org.jetbrains.kotlinx.dataframe.ColumnsSelector
44
import org.jetbrains.kotlinx.dataframe.DataFrame
5-
import org.jetbrains.kotlinx.dataframe.api.Corr
6-
import org.jetbrains.kotlinx.dataframe.api.cast
7-
import org.jetbrains.kotlinx.dataframe.api.castToNotNullable
8-
import org.jetbrains.kotlinx.dataframe.api.convertToDouble
9-
import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
10-
import org.jetbrains.kotlinx.dataframe.api.getColumnsWithPaths
11-
import org.jetbrains.kotlinx.dataframe.api.isColumnGroup
12-
import org.jetbrains.kotlinx.dataframe.api.isSuitableForCorr
13-
import org.jetbrains.kotlinx.dataframe.api.name
14-
import org.jetbrains.kotlinx.dataframe.api.toValueColumn
5+
import org.jetbrains.kotlinx.dataframe.api.*
156
import org.jetbrains.kotlinx.dataframe.columns.ColumnPath
167
import org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath
178
import org.jetbrains.kotlinx.dataframe.math.varianceAndMean
@@ -25,7 +16,7 @@ internal fun <T, C, R> Corr<T, C>.corrImpl(otherColumns: ColumnsSelector<T, R>):
2516
// extract nested number columns from ColumnGroups
2617
if (it.isColumnGroup()) {
2718
val groupPath = it.path
28-
df.getColumnsWithPaths { groupPath.dfs { it.isSuitableForCorr() } }.map { it.cast() }
19+
df.getColumnsWithPaths { groupPath.cols { it.isSuitableForCorr() }.rec() }.map { it.cast() }
2920
} else listOf(it)
3021
}
3122

0 commit comments

Comments
 (0)