diff --git a/core/api/core.api b/core/api/core.api index f764cd4945..0a8cef835a 100644 --- a/core/api/core.api +++ b/core/api/core.api @@ -878,11 +878,16 @@ public abstract interface class org/jetbrains/kotlinx/dataframe/api/ColGroupsCol } public abstract interface class org/jetbrains/kotlinx/dataframe/api/ColsAtAnyDepthColumnsSelectionDsl { + public fun colsAtAnyDepth (Ljava/lang/String;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet; public fun colsAtAnyDepth (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet; public fun colsAtAnyDepth (Lkotlin/reflect/KProperty;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet; + public fun colsAtAnyDepth (Lorg/jetbrains/kotlinx/dataframe/api/ColumnsSelectionDsl;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet; public fun colsAtAnyDepth (Lorg/jetbrains/kotlinx/dataframe/api/ColumnsSelectionDsl;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet; + public fun colsAtAnyDepth (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnPath;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet; public fun colsAtAnyDepth (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnPath;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet; + public fun colsAtAnyDepth (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet; public fun colsAtAnyDepth (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet; + public fun colsAtAnyDepth (Lorg/jetbrains/kotlinx/dataframe/columns/SingleColumn;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet; public fun colsAtAnyDepth (Lorg/jetbrains/kotlinx/dataframe/columns/SingleColumn;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet; public static synthetic fun colsAtAnyDepth$default (Lorg/jetbrains/kotlinx/dataframe/api/ColsAtAnyDepthColumnsSelectionDsl;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet; public static synthetic fun colsAtAnyDepth$default (Lorg/jetbrains/kotlinx/dataframe/api/ColsAtAnyDepthColumnsSelectionDsl;Lkotlin/reflect/KProperty;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet; @@ -1018,11 +1023,16 @@ public abstract interface class org/jetbrains/kotlinx/dataframe/api/ColsColumnsS } public abstract interface class org/jetbrains/kotlinx/dataframe/api/ColsInGroupsColumnsSelectionDsl { + public fun colsInGroups (Ljava/lang/String;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableColumnSet; public fun colsInGroups (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableColumnSet; public fun colsInGroups (Lkotlin/reflect/KProperty;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableColumnSet; + public fun colsInGroups (Lorg/jetbrains/kotlinx/dataframe/api/ColumnsSelectionDsl;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableColumnSet; public fun colsInGroups (Lorg/jetbrains/kotlinx/dataframe/api/ColumnsSelectionDsl;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableColumnSet; + public fun colsInGroups (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnPath;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableColumnSet; public fun colsInGroups (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnPath;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableColumnSet; + public fun colsInGroups (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableColumnSet; public fun colsInGroups (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableColumnSet; + public fun colsInGroups (Lorg/jetbrains/kotlinx/dataframe/columns/SingleColumn;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableColumnSet; public fun colsInGroups (Lorg/jetbrains/kotlinx/dataframe/columns/SingleColumn;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableColumnSet; public static synthetic fun colsInGroups$default (Lorg/jetbrains/kotlinx/dataframe/api/ColsInGroupsColumnsSelectionDsl;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableColumnSet; public static synthetic fun colsInGroups$default (Lorg/jetbrains/kotlinx/dataframe/api/ColsInGroupsColumnsSelectionDsl;Lkotlin/reflect/KProperty;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableColumnSet; @@ -3937,13 +3947,17 @@ public abstract interface class org/jetbrains/kotlinx/dataframe/api/SimplifyColu } public abstract interface class org/jetbrains/kotlinx/dataframe/api/SingleColumnsSelectionDsl { + public fun single (Lorg/jetbrains/kotlinx/dataframe/api/ColumnsSelectionDsl;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableSingleColumn; public fun single (Lorg/jetbrains/kotlinx/dataframe/api/ColumnsSelectionDsl;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableSingleColumn; + public fun single (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableSingleColumn; public fun single (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableSingleColumn; public static synthetic fun single$default (Lorg/jetbrains/kotlinx/dataframe/api/SingleColumnsSelectionDsl;Lorg/jetbrains/kotlinx/dataframe/api/ColumnsSelectionDsl;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableSingleColumn; public static synthetic fun single$default (Lorg/jetbrains/kotlinx/dataframe/api/SingleColumnsSelectionDsl;Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableSingleColumn; + public fun singleCol (Ljava/lang/String;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableSingleColumn; public fun singleCol (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableSingleColumn; public fun singleCol (Lkotlin/reflect/KProperty;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableSingleColumn; public fun singleCol (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnPath;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableSingleColumn; + public fun singleCol (Lorg/jetbrains/kotlinx/dataframe/columns/SingleColumn;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableSingleColumn; public fun singleCol (Lorg/jetbrains/kotlinx/dataframe/columns/SingleColumn;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableSingleColumn; public static synthetic fun singleCol$default (Lorg/jetbrains/kotlinx/dataframe/api/SingleColumnsSelectionDsl;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableSingleColumn; public static synthetic fun singleCol$default (Lorg/jetbrains/kotlinx/dataframe/api/SingleColumnsSelectionDsl;Lkotlin/reflect/KProperty;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableSingleColumn; diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/colsAtAnyDepth.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/colsAtAnyDepth.kt index ba878e0786..b5eb8e6d5c 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/colsAtAnyDepth.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/colsAtAnyDepth.kt @@ -65,8 +65,7 @@ public interface ColsAtAnyDepthColumnsSelectionDsl { /** * ## Cols At Any Depth * - * Returns all columns in [this\] at any depth (so also inside [Column Groups][ColumnGroup]) if they satisfy the - * optional given predicate. + * Returns all columns in [this\] at any depth (so also inside [Column Groups][ColumnGroup]) * * This function can also be followed by another [ColumnSet] filter function like * [colsOf][ColumnsSelectionDsl.colsOf], [single][ColumnsSelectionDsl.single], or [valueCols][ColumnsSelectionDsl.valueCols]. @@ -74,7 +73,7 @@ public interface ColsAtAnyDepthColumnsSelectionDsl { * #### For example: * `// Depth-first search to a column containing the value "Alice"` * - * `df.`[select][DataFrame.select]` { `[colsAtAnyDepth][ColumnsSelectionDsl.colsAtAnyDepth]`().`[first][ColumnsSelectionDsl.firstCol]` { "Alice" `[in][Iterable.contains]` it.`[values][DataColumn.values]`() } }` + * `df.`[select][DataFrame.select]` { `[colsAtAnyDepth][ColumnsSelectionDsl.colsAtAnyDepth]`().`[filter][FilterColumnsSelectionDsl.filter]` { "Alice" `[in][Iterable.contains]` it.`[values][DataColumn.values]`() }.`[first][ColumnsSelectionDsl.firstCol]`() }` * {@include [LineBreak]} * `// The columns at any depth excluding the top-level` * @@ -82,7 +81,7 @@ public interface ColsAtAnyDepthColumnsSelectionDsl { * {@include [LineBreak]} * `// All value- and frame columns at any depth` * - * `df.`[select][DataFrame.select]` { `[colsAtAnyDepth][ColumnsSelectionDsl.colsAtAnyDepth]` { !it.`[isColumnGroup][DataColumn.isColumnGroup]` } }` + * `df.`[select][DataFrame.select]` { `[colsAtAnyDepth][ColumnsSelectionDsl.colsAtAnyDepth]`().`[filter][FilterColumnsSelectionDsl.filter]` { !it.`[isColumnGroup][DataColumn.isColumnGroup]` } }` * {@include [LineBreak]} * `// All value columns at any depth nested under a column group named "myColGroup"` * @@ -94,13 +93,13 @@ public interface ColsAtAnyDepthColumnsSelectionDsl { * * #### Converting from deprecated syntax: * - * `dfs { condition } -> `[colsAtAnyDepth][colsAtAnyDepth]` { condition }` + * `dfs { condition } -> `[colsAtAnyDepth][colsAtAnyDepth]`().`[filter][FilterColumnsSelectionDsl.filter]` { condition }` * - * `allDfs(includeGroups = false) -> `[colsAtAnyDepth][colsAtAnyDepth]` { includeGroups || !it.`[isColumnGroup][DataColumn.isColumnGroup]`() }` + * `allDfs(includeGroups = false) -> `[colsAtAnyDepth][colsAtAnyDepth]`().`[filter][FilterColumnsSelectionDsl.filter]` { includeGroups || !it.`[isColumnGroup][DataColumn.isColumnGroup]`() }` * * `dfsOf { condition } -> `[colsAtAnyDepth][colsAtAnyDepth]`().`[colsOf][ColumnsSelectionDsl.colsOf]` { condition }` * - * [cols][ColumnsSelectionDsl.cols]` { condition }.`[recursively][recursively]`() -> `[colsAtAnyDepth][colsAtAnyDepth]` { condition }` + * [cols][ColumnsSelectionDsl.cols]` { condition }.`[recursively][recursively]`() -> `[colsAtAnyDepth][colsAtAnyDepth]`().`[filter][FilterColumnsSelectionDsl.filter]` { condition }` * * [first][ColumnsSelectionDsl.first]` { condition }.`[rec][rec]`() -> `[colsAtAnyDepth][colsAtAnyDepth]` { condition }.`[first][ColumnsSelectionDsl.first]`()` * @@ -122,6 +121,7 @@ public interface ColsAtAnyDepthColumnsSelectionDsl { * `df.`[select][DataFrame.select]` { `[colGroups][ColumnsSelectionDsl.colGroups]`().`[colsAtAnyDepth][ColumnsSelectionDsl.colsAtAnyDepth]` { "Alice" `[in][Iterable.contains]` it.`[values][DataColumn.values]`() } }` */ @Interpretable("ColsAtAnyDepth0") + @Deprecated("", replaceWith = ReplaceWith("colsAtAnyDepth().filter(predicate)")) public fun ColumnSet<*>.colsAtAnyDepth(predicate: ColumnFilter<*> = { true }): ColumnSet<*> = colsAtAnyDepthInternal(predicate) @@ -129,14 +129,35 @@ public interface ColsAtAnyDepthColumnsSelectionDsl { * @include [CommonAtAnyDepthDocs] * @set [CommonAtAnyDepthDocs.Examples] * - * `df.`[select][DataFrame.select]` { `[colsAtAnyDepth][ColumnsSelectionDsl.colsAtAnyDepth]` { "Alice" `[in][Iterable.contains]` it.`[values][DataColumn.values]`() }.`[first][ColumnsSelectionDsl.first]`() }` + * `df.`[select][DataFrame.select]` { `[colGroups][ColumnsSelectionDsl.colGroups]`().`[colsAtAnyDepth][ColumnsSelectionDsl.colsAtAnyDepth]`().filter { "Alice" `[in][Iterable.contains]` it.`[values][DataColumn.values]`() } }` + */ + @Interpretable("ColsAtAnyDepth0") + public fun ColumnSet<*>.colsAtAnyDepth(): ColumnSet<*> = colsAtAnyDepthInternal { true } + + /** + * @include [CommonAtAnyDepthDocs] + * @set [CommonAtAnyDepthDocs.Examples] + * + * `df.`[select][DataFrame.select]` { `[colsAtAnyDepth][ColumnsSelectionDsl.colsAtAnyDepth]` { "Alice" `[in][Iterable.contains]` it.`[values][DataColumn.values]`() }.`[first][ColumnsSelectionDsl.first]`() }` * * `df.`[select][DataFrame.select]` { `[colsAtAnyDepth][ColumnsSelectionDsl.colsAtAnyDepth]` { !it.`[isColumnGroup][DataColumn.isColumnGroup]` } }` */ @Interpretable("ColsAtAnyDepth1") + @Deprecated("", replaceWith = ReplaceWith("colsAtAnyDepth().filter(predicate)")) public fun ColumnsSelectionDsl<*>.colsAtAnyDepth(predicate: ColumnFilter<*> = { true }): ColumnSet<*> = asSingleColumn().colsAtAnyDepthInternal(predicate) + /** + * @include [CommonAtAnyDepthDocs] + * @set [CommonAtAnyDepthDocs.Examples] + * + * `df.`[select][DataFrame.select]` { `[colsAtAnyDepth][ColumnsSelectionDsl.colsAtAnyDepth]`().filter { "Alice" `[in][Iterable.contains]` it.`[values][DataColumn.values]`() }.`[first][ColumnsSelectionDsl.first]`() }` + * + * `df.`[select][DataFrame.select]` { `[colsAtAnyDepth][ColumnsSelectionDsl.colsAtAnyDepth]`().filter { !it.`[isColumnGroup][DataColumn.isColumnGroup]` } }` + */ + @Interpretable("ColsAtAnyDepth1") + public fun ColumnsSelectionDsl<*>.colsAtAnyDepth(): ColumnSet<*> = asSingleColumn().colsAtAnyDepthInternal { true } + /** * @include [CommonAtAnyDepthDocs] * @set [CommonAtAnyDepthDocs.Examples] @@ -144,18 +165,38 @@ public interface ColsAtAnyDepthColumnsSelectionDsl { * `df.`[select][DataFrame.select]` { myColGroup.`[colsAtAnyDepth][SingleColumn.colsAtAnyDepth]` { "Alice" `[in][Iterable.contains]` it.`[values][DataColumn.values]`() } }` */ @Interpretable("ColsAtAnyDepth2") + @Deprecated("", replaceWith = ReplaceWith("colsAtAnyDepth().filter(predicate)")) public fun SingleColumn>.colsAtAnyDepth(predicate: ColumnFilter<*> = { true }): ColumnSet<*> = ensureIsColumnGroup().colsAtAnyDepthInternal(predicate) + /** + * @include [CommonAtAnyDepthDocs] + * @set [CommonAtAnyDepthDocs.Examples] + * + * `df.`[select][DataFrame.select]` { myColGroup.`[colsAtAnyDepth][SingleColumn.colsAtAnyDepth]`().filter { "Alice" `[in][Iterable.contains]` it.`[values][DataColumn.values]`() } }` + */ + @Interpretable("ColsAtAnyDepth2") + public fun SingleColumn>.colsAtAnyDepth(): ColumnSet<*> = + ensureIsColumnGroup().colsAtAnyDepthInternal { true } + /** * @include [CommonAtAnyDepthDocs] * @set [CommonAtAnyDepthDocs.Examples] * * `df.`[select][DataFrame.select]` { "myColumnGroup".`[colsAtAnyDepth][String.colsAtAnyDepth]` { "Alice" `[in][Iterable.contains]` it.`[values][DataColumn.values]`() } }` */ + @Deprecated("", replaceWith = ReplaceWith("colsAtAnyDepth().filter(predicate)")) public fun String.colsAtAnyDepth(predicate: ColumnFilter<*> = { true }): ColumnSet<*> = columnGroup(this).colsAtAnyDepth(predicate) + /** + * @include [CommonAtAnyDepthDocs] + * @set [CommonAtAnyDepthDocs.Examples] + * + * `df.`[select][DataFrame.select]` { "myColumnGroup".`[colsAtAnyDepth][String.colsAtAnyDepth]`().filter { "Alice" `[in][Iterable.contains]` it.`[values][DataColumn.values]`() } }` + */ + public fun String.colsAtAnyDepth(): ColumnSet<*> = columnGroup(this).colsAtAnyDepth { true } + /** * @include [CommonAtAnyDepthDocs] * @set [CommonAtAnyDepthDocs.Examples] @@ -175,9 +216,18 @@ public interface ColsAtAnyDepthColumnsSelectionDsl { * * `df.`[select][DataFrame.select]` { "pathTo"["myGroupCol"].`[colsAtAnyDepth][ColumnsSelectionDsl.colsAtAnyDepth]` { "Alice" `[in][Iterable.contains]` it.`[values][DataColumn.values]`() } }` */ + @Deprecated("", replaceWith = ReplaceWith("colsAtAnyDepth().filter(predicate)")) public fun ColumnPath.colsAtAnyDepth(predicate: ColumnFilter<*> = { true }): ColumnSet<*> = columnGroup(this).colsAtAnyDepth(predicate) + /** + * @include [CommonAtAnyDepthDocs] + * @set [CommonAtAnyDepthDocs.Examples] + * + * `df.`[select][DataFrame.select]` { "pathTo"["myGroupCol"].`[colsAtAnyDepth][ColumnsSelectionDsl.colsAtAnyDepth]`().filter { "Alice" `[in][Iterable.contains]` it.`[values][DataColumn.values]`() } }` + */ + public fun ColumnPath.colsAtAnyDepth(): ColumnSet<*> = columnGroup(this).colsAtAnyDepth { true } + // endregion } diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/colsInGroups.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/colsInGroups.kt index a143c2c581..aa71c1df35 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/colsInGroups.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/colsInGroups.kt @@ -65,7 +65,7 @@ public interface ColsInGroupsColumnsSelectionDsl { /** * ## Cols in Groups * - * [colsInGroups][colsInGroups] is a function that returns all (optionally filtered) columns at the top-levels of + * [colsInGroups][colsInGroups] is a function that returns all columns at the top-levels of * all [column groups][ColumnGroup] in [this\]. This is useful if you want to select all columns that are * "one level deeper". * @@ -87,11 +87,11 @@ public interface ColsInGroupsColumnsSelectionDsl { * * and * - * `df.`[select][DataFrame.select]` { `[colsInGroups][ColumnsSelectionDsl.colsInGroups]` { "user" `[in][String.contains]` it.`[name][DataColumn.name]` } }` + * `df.`[select][DataFrame.select]` { `[colsInGroups][ColumnsSelectionDsl.colsInGroups]`().`[nameContains][ColumnsSelectionDsl.nameContains]`("user") }` * {@include [LineBreak]} * Similarly, you can take the columns inside all [column groups][ColumnGroup] in a [ColumnSet]: * {@include [LineBreak]} - * `df.`[select][DataFrame.select]` { `[colGroups][ColumnsSelectionDsl.colGroups]` { "my" `[in][String.contains]` it.`[name][DataColumn.name]` }.`[colsInGroups][ColumnSet.colsInGroups]`() }` + * `df.`[select][DataFrame.select]` { `[colGroups][ColumnsSelectionDsl.colGroups]`().`[nameContains][ColumnsSelectionDsl.nameContains]`("my").`[colsInGroups][ColumnSet.colsInGroups]`() }` * {@include [LineBreak]} * * #### Examples of this overload: @@ -100,8 +100,7 @@ public interface ColsInGroupsColumnsSelectionDsl { * * @see [ColumnsSelectionDsl.cols\] * @see [ColumnsSelectionDsl.colGroups\] - * @param [predicate\] An optional predicate to filter the cols by. - * @return A [TransformableColumnSet] containing the (filtered) cols. + * @return A [TransformableColumnSet] containing the cols. */ private interface ColsInGroupsDocs { @@ -117,9 +116,18 @@ public interface ColsInGroupsColumnsSelectionDsl { * * `df.`[select][DataFrame.select]` { `[colsOf][ColumnsSelectionDsl.colsOf]`<`[DataRow][DataRow]`>().`[colsInGroups][ColumnSet.colsInGroups]`() }` */ + @Deprecated("", ReplaceWith("this.colsInGroups().filter(predicate)")) public fun ColumnSet<*>.colsInGroups(predicate: ColumnFilter<*> = { true }): TransformableColumnSet<*> = transform { it.flatMap { it.cols().filter { predicate(it) } } } + /** + * @include [ColsInGroupsDocs] + * @set [ColsInGroupsDocs.EXAMPLE] + * + * `df.`[select][DataFrame.select]` { `[colsOf][ColumnsSelectionDsl.colsOf]`<`[DataRow][DataRow]`>().`[colsInGroups][ColumnSet.colsInGroups]`() }` + */ + public fun ColumnSet<*>.colsInGroups(): TransformableColumnSet<*> = transform { it.flatMap { it.cols() } } + /** * @include [ColsInGroupsDocs] * @set [ColsInGroupsDocs.EXAMPLE] @@ -128,9 +136,18 @@ public interface ColsInGroupsColumnsSelectionDsl { * * `df.`[select][DataFrame.select]` { `[colsInGroups][ColumnSet.colsInGroups]`() }` */ + @Deprecated("", ReplaceWith("colsInGroups().filter(predicate)")) public fun ColumnsSelectionDsl<*>.colsInGroups(predicate: ColumnFilter<*> = { true }): TransformableColumnSet<*> = asSingleColumn().colsInGroups(predicate) + /** + * @include [ColsInGroupsDocs] + * @set [ColsInGroupsDocs.EXAMPLE] + * + * `df.`[select][DataFrame.select]` { `[colsInGroups][ColumnSet.colsInGroups]`() }` + */ + public fun ColumnsSelectionDsl<*>.colsInGroups(): TransformableColumnSet<*> = asSingleColumn().colsInGroups() + /** * @include [ColsInGroupsDocs] * @set [ColsInGroupsDocs.EXAMPLE] @@ -139,18 +156,37 @@ public interface ColsInGroupsColumnsSelectionDsl { * * `df.`[select][DataFrame.select]` { myColumnGroup.`[colsInGroups][SingleColumn.colsInGroups]` { it.`[any][ColumnWithPath.any]` { it == "Alice" } } }` */ + @Deprecated("", ReplaceWith("this.colsInGroups().filter(predicate)")) public fun SingleColumn>.colsInGroups(predicate: ColumnFilter<*> = { true }): TransformableColumnSet<*> = ensureIsColumnGroup().allColumnsInternal().colsInGroups(predicate) + /** + * @include [ColsInGroupsDocs] + * @set [ColsInGroupsDocs.EXAMPLE] + * + * `df.`[select][DataFrame.select]` { myColumnGroup.`[colsInGroups][SingleColumn.colsInGroups]` { it.`[any][ColumnWithPath.any]` { it == "Alice" } } }` + */ + public fun SingleColumn>.colsInGroups(): TransformableColumnSet<*> = + ensureIsColumnGroup().allColumnsInternal().colsInGroups() + /** * @include [ColsInGroupsDocs] * @set [ColsInGroupsDocs.EXAMPLE] * * `df.`[select][DataFrame.select]` { "myColumnGroup".`[colsInGroups][String.colsInGroups]`() }` */ + @Deprecated("", ReplaceWith("colsInGroups().filter(predicate)")) public fun String.colsInGroups(predicate: ColumnFilter<*> = { true }): TransformableColumnSet<*> = columnGroup(this).colsInGroups(predicate) + /** + * @include [ColsInGroupsDocs] + * @set [ColsInGroupsDocs.EXAMPLE] + * + * `df.`[select][DataFrame.select]` { "myColumnGroup".`[colsInGroups][String.colsInGroups]`() }` + */ + public fun String.colsInGroups(): TransformableColumnSet<*> = columnGroup(this).colsInGroups() + /** * @include [ColsInGroupsDocs] * @set [ColsInGroupsDocs.EXAMPLE] @@ -172,8 +208,17 @@ public interface ColsInGroupsColumnsSelectionDsl { * * `df.`[select][DataFrame.select]` { "pathTo"["myColumnGroup"].`[colsInGroups][ColumnPath.colsInGroups]`() }` */ + @Deprecated("", ReplaceWith("colsInGroups().filter(predicate)")) public fun ColumnPath.colsInGroups(predicate: ColumnFilter<*> = { true }): TransformableColumnSet<*> = columnGroup(this).colsInGroups(predicate) + + /** + * @include [ColsInGroupsDocs] + * @set [ColsInGroupsDocs.EXAMPLE] + * + * `df.`[select][DataFrame.select]` { "pathTo"["myColumnGroup"].`[colsInGroups][ColumnPath.colsInGroups]`() }` + */ + public fun ColumnPath.colsInGroups(): TransformableColumnSet<*> = columnGroup(this).colsInGroups() } // endregion diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/corr.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/corr.kt index 9bc6de7d28..803aa5e272 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/corr.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/corr.kt @@ -16,7 +16,10 @@ internal fun AnyCol.isSuitableForCorr() = isSubtypeOf() || type() == typ public data class Corr(internal val df: DataFrame, internal val columns: ColumnsSelector) -public fun DataFrame.corr(): DataFrame = corr { colsAtAnyDepth { it.isSuitableForCorr() } }.withItself() +public fun DataFrame.corr(): DataFrame = + corr { + colsAtAnyDepth().filter { it.isSuitableForCorr() } + }.withItself() public fun DataFrame.corr(columns: ColumnsSelector): Corr = Corr(this, columns) diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/cumSum.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/cumSum.kt index effb6d0431..df100d93bb 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/cumSum.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/cumSum.kt @@ -159,7 +159,7 @@ public fun DataFrame.cumSum( public fun DataFrame.cumSum(skipNA: Boolean = defaultCumSumSkipNA): DataFrame = cumSum(skipNA) { // TODO keep at any depth? - colsAtAnyDepth { it.isNumber() }.cast() + colsAtAnyDepth().filter { it.isNumber() }.cast() } // endregion @@ -216,7 +216,7 @@ public fun GroupBy.cumSum( public fun GroupBy.cumSum(skipNA: Boolean = defaultCumSumSkipNA): GroupBy = cumSum(skipNA) { // TODO keep at any depth? - colsAtAnyDepth { it.isNumber() }.cast() + colsAtAnyDepth().filter { it.isNumber() }.cast() } // endregion diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/describe.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/describe.kt index 1b340e233f..9891616c00 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/describe.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/describe.kt @@ -120,7 +120,7 @@ public fun DataColumn.describe(): DataFrame = describe */ public fun DataFrame.describe(): DataFrame = describe { - colsAtAnyDepth { !it.isColumnGroup() } + colsAtAnyDepth().filter { !it.isColumnGroup() } } /** diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/explode.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/explode.kt index 0f36cd226b..d3762fb7eb 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/explode.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/explode.kt @@ -13,7 +13,9 @@ import org.jetbrains.kotlinx.dataframe.columns.toColumnSet import org.jetbrains.kotlinx.dataframe.impl.api.explodeImpl import kotlin.reflect.KProperty -private val defaultExplodeColumns: ColumnsSelector<*, *> = { colsAtAnyDepth { it.isList() || it.isFrameColumn() } } +private val defaultExplodeColumns: ColumnsSelector<*, *> = { + colsAtAnyDepth().filter { it.isList() || it.isFrameColumn() } +} // region explode DataFrame @Refine diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/inferType.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/inferType.kt index 91a73ba6ad..9b6cd4b6ee 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/inferType.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/inferType.kt @@ -21,7 +21,10 @@ public fun AnyCol.inferType(): DataColumn<*> = // region DataFrame -public fun DataFrame.inferType(): DataFrame = inferType { colsAtAnyDepth { !it.isColumnGroup() } } +public fun DataFrame.inferType(): DataFrame = + inferType { + colsAtAnyDepth().filter { !it.isColumnGroup() } + } public fun DataFrame.inferType(columns: ColumnsSelector): DataFrame = replace(columns).with { it.inferType() } diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/parse.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/parse.kt index 601e008d66..04e8336f5c 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/parse.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/parse.kt @@ -214,7 +214,7 @@ public fun DataColumn.tryParse(options: ParserOptions? = null): DataCol public fun DataFrame.parse(options: ParserOptions? = null): DataFrame = parse(options) { - colsAtAnyDepth { !it.isColumnGroup() } + colsAtAnyDepth().filter { !it.isColumnGroup() } } /** diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/replace.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/replace.kt index 9749c196bb..963cc2ff80 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/replace.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/replace.kt @@ -36,7 +36,7 @@ public fun DataFrame.replace(vararg columns: KProperty): ReplaceCla public fun DataFrame.replaceAll( vararg valuePairs: Pair, - columns: ColumnsSelector = { colsAtAnyDepth { !it.isColumnGroup() } }, + columns: ColumnsSelector = { colsAtAnyDepth().filter { !it.isColumnGroup() } }, ): DataFrame { val map = valuePairs.toMap() return update(columns).with { map[it] ?: it } diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/single.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/single.kt index a6f02b6a76..0ff8ec69a6 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/single.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/single.kt @@ -96,9 +96,9 @@ public interface SingleColumnsSelectionDsl { /** * ## Single (Col) - * Returns the single column from [this\] that adheres to the optional given [condition\]. - * If no column adheres to the given [condition\], [NoSuchElementException] is thrown. - * If multiple columns adhere to it, [IllegalArgumentException] is thrown. + * Returns the single column from [this\]. + * If there is no column, [NoSuchElementException] is thrown. + * If there are multiple columns, [IllegalArgumentException] is thrown. * * This function operates solely on columns at the top-level. * @@ -108,18 +108,17 @@ public interface SingleColumnsSelectionDsl { * * #### Examples: * - * `df.`[select][DataFrame.select]` { `[single][ColumnsSelectionDsl.single]` { it.`[name][ColumnReference.name]`().`[startsWith][String.startsWith]`("order") } }` + * `df.`[select][DataFrame.select]` { `[nameStartsWith][ColumnsSelectionDsl.nameStartsWith]`("order").`[single][ColumnsSelectionDsl.single]`() }` * - * `df.`[select][DataFrame.select]` { "myColumnGroup".`[singleCol][String.singleCol]` { it.`[name][ColumnReference.name]`().`[startsWith][String.startsWith]`("order") } }` + * `df.`[select][DataFrame.select]` { "myColumnGroup".`[colsNameStartsWith][ColumnNameFiltersColumnsSelectionDsl.colsNameStartsWith]`("order").`[singleCol][String.singleCol]`() }` * * #### Examples for this overload: * * {@get [Examples]} * - * @param [condition\] The optional [ColumnFilter] condition that the column must adhere to. - * @return A [SingleColumn] containing the single column that adheres to the given [condition\]. - * @throws [NoSuchElementException\] if no column adheres to the given [condition\]. - * @throws [IllegalArgumentException\] if more than one column adheres to the given [condition\]. + * @return A [SingleColumn] containing the single column. + * @throws [NoSuchElementException\] if there are no columns in [this\]. + * @throws [IllegalArgumentException\] if there is more than one column in [this\]. */ private interface CommonSingleDocs { @@ -135,9 +134,20 @@ public interface SingleColumnsSelectionDsl { * `df.`[select][DataFrame.select]` { `[colsOf][SingleColumn.colsOf]`<`[Int][Int]`>().`[single][ColumnSet.single]`() }` */ @Interpretable("Single0") + @Deprecated("", ReplaceWith("this.filter(condition).single()")) public fun ColumnSet.single(condition: ColumnFilter = { true }): TransformableSingleColumn = singleInternal(condition) + /** + * @include [CommonSingleDocs] + * @set [CommonSingleDocs.Examples] + * `df.`[select][DataFrame.select]` { `[colsOf][SingleColumn.colsOf]`<`[String][String]`>().nameStartsWith("year").`[single][ColumnSet.single]`() }` + * + * `df.`[select][DataFrame.select]` { `[colsOf][SingleColumn.colsOf]`<`[Int][Int]`>().`[single][ColumnSet.single]`() }` + */ + @Interpretable("Single0") + public fun ColumnSet.single(): TransformableSingleColumn = singleInternal { true } + /** * @include [CommonSingleDocs] * @set [CommonSingleDocs.Examples] @@ -145,9 +155,19 @@ public interface SingleColumnsSelectionDsl { * `df.`[select][DataFrame.select]` { `[single][ColumnsSelectionDsl.single]` { it.`[name][ColumnReference.name]`().`[startsWith][String.startsWith]`("year") } }` */ @Interpretable("Single1") + @Deprecated("", ReplaceWith("cols().filter(condition).single()")) public fun ColumnsSelectionDsl<*>.single(condition: ColumnFilter<*> = { true }): TransformableSingleColumn<*> = asSingleColumn().singleCol(condition) + /** + * @include [CommonSingleDocs] + * @set [CommonSingleDocs.Examples] + * + * `df.`[select][DataFrame.select]` { nameStartsWith("year").`[single][ColumnsSelectionDsl.single]`() }` + */ + @Interpretable("Single1") + public fun ColumnsSelectionDsl<*>.single(): TransformableSingleColumn<*> = asSingleColumn().singleCol { true } + /** * @include [CommonSingleDocs] * @set [CommonSingleDocs.Examples] @@ -155,17 +175,36 @@ public interface SingleColumnsSelectionDsl { * `df.`[select][DataFrame.select]` { myColumnGroup.`[singleCol][SingleColumn.singleCol]`() }` */ @Interpretable("Single2") + @Deprecated("", ReplaceWith("this.cols().filter(condition).single()")) public fun SingleColumn>.singleCol(condition: ColumnFilter<*> = { true }): TransformableSingleColumn<*> = this.ensureIsColumnGroup().asColumnSet().single(condition) + /** + * @include [CommonSingleDocs] + * @set [CommonSingleDocs.Examples] + * + * `df.`[select][DataFrame.select]` { myColumnGroup.`[singleCol][SingleColumn.singleCol]`() }` + */ + @Interpretable("Single2") + public fun SingleColumn>.singleCol(): TransformableSingleColumn<*> = + this.ensureIsColumnGroup().asColumnSet().single() + /** * @include [CommonSingleDocs] * @set [CommonSingleDocs.Examples] * `df.`[select][DataFrame.select]` { "myColumnGroup".`[singleCol][String.singleCol]` { it.`[name][ColumnReference.name]`().`[startsWith][String.startsWith]`("year") } }` */ + @Deprecated("", ReplaceWith("this.cols().filter(condition).single()")) public fun String.singleCol(condition: ColumnFilter<*> = { true }): TransformableSingleColumn<*> = columnGroup(this).singleCol(condition) + /** + * @include [CommonSingleDocs] + * @set [CommonSingleDocs.Examples] + * `df.`[select][DataFrame.select]` { "myColumnGroup".`[colsNameStartsWith][ColumnNameFiltersColumnsSelectionDsl.colsNameStartsWith]`("year").`[singleCol][String.singleCol]`() }` + */ + public fun String.singleCol(): TransformableSingleColumn<*> = columnGroup(this).singleCol() + /** * @include [CommonSingleDocs] * @set [CommonSingleDocs.Examples] diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/xs.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/xs.kt index 4a99a5a15b..21d932046c 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/xs.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/xs.kt @@ -12,7 +12,7 @@ import org.jetbrains.kotlinx.dataframe.impl.api.xsImpl @Interpretable("DataFrameXs") public fun DataFrame.xs(vararg keyValues: Any?): DataFrame = xs(*keyValues) { - colsAtAnyDepth { !it.isColumnGroup() }.take(keyValues.size) + colsAtAnyDepth().filter { !it.isColumnGroup() }.take(keyValues.size) } @Refine @@ -28,7 +28,7 @@ public fun DataFrame.xs(vararg keyValues: C, keyColumns: ColumnsSelect @Interpretable("GroupByXs") public fun GroupBy.xs(vararg keyValues: Any?): GroupBy = xs(*keyValues) { - colsAtAnyDepth { !it.isColumnGroup() }.take(keyValues.size) + colsAtAnyDepth().filter { !it.isColumnGroup() }.take(keyValues.size) } @Refine diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/GroupByImpl.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/GroupByImpl.kt index 5d150f979a..eab8acff76 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/GroupByImpl.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/GroupByImpl.kt @@ -107,7 +107,9 @@ internal fun aggregateGroupBy( if (!removeColumns) removedNode.data.wasRemoved = false - val columnsToInsert = groupedFrame.getColumnsWithPaths { colsAtAnyDepth { !it.isColumnGroup() } }.map { + val columnsToInsert = groupedFrame.getColumnsWithPaths { + colsAtAnyDepth().filter { !it.isColumnGroup() } + }.map { ColumnToInsert(insertPath + it.path, it, removedNode) } val src = if (removeColumns) removed.df else df diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/corr.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/corr.kt index c4fb2d78f5..bbdd412851 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/corr.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/corr.kt @@ -26,7 +26,9 @@ internal fun Corr.corrImpl(otherColumns: ColumnsSelector): // extract nested number columns from ColumnGroups if (it.isColumnGroup()) { val groupPath = it.path - df.getColumnsWithPaths { groupPath.colsAtAnyDepth { it.isSuitableForCorr() } }.map { it.cast() } + df.getColumnsWithPaths { + groupPath.colsAtAnyDepth().filter { it.isSuitableForCorr() } + }.map { it.cast() } } else { listOf(it) } diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/join.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/join.kt index f353ab48e5..399d74bd62 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/join.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/join.kt @@ -67,10 +67,10 @@ internal fun DataFrame.joinImpl( val rightCol = rightJoinColumns[i] if (leftCol.isColumnGroup() && rightCol.isColumnGroup()) { val leftColumns = getColumnsWithPaths { - leftCol.colsAtAnyDepth { !it.isColumnGroup() } + leftCol.colsAtAnyDepth().filter { !it.isColumnGroup() } } val rightColumns = other.getColumnsWithPaths { - rightCol.colsAtAnyDepth { !it.isColumnGroup() } + rightCol.colsAtAnyDepth().filter { !it.isColumnGroup() } } val leftPrefixLength = leftCol.path.size @@ -112,7 +112,7 @@ internal fun DataFrame.joinImpl( // group row indices by key from right data frame val groupedRight = when (joinType) { - JoinType.Exclude -> rightJoinKeyToIndex.associate { it.first to emptyList() } + JoinType.Exclude -> rightJoinKeyToIndex.associate { it.first to emptyList() } else -> rightJoinKeyToIndex.groupBy({ it.first }) { it.second } } @@ -145,14 +145,14 @@ internal fun DataFrame.joinImpl( outputRowsCount += rightUnmatchedCount } - val leftColumns = getColumnsWithPaths { colsAtAnyDepth { !it.isColumnGroup() } } + val leftColumns = getColumnsWithPaths { colsAtAnyDepth().filter { !it.isColumnGroup() } } val rightJoinColumnPaths = allRightJoinColumns.associate { it.path to it.data } val newRightColumns = if (addNewColumns) { other.getColumnsWithPaths { - colsAtAnyDepth { + colsAtAnyDepth().filter { !it.isColumnGroup() && !rightJoinColumnPaths.contains(it.path) } } diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/parse.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/parse.kt index e0a19d9eff..04fb4d4ea0 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/parse.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/parse.kt @@ -681,7 +681,7 @@ internal fun DataFrame.parseImpl(options: ParserOptions?, columns: Column col.isFrameColumn() -> { col.map { it.parseImpl(options) { - colsAtAnyDepth { !it.isColumnGroup() } + colsAtAnyDepth().filter { !it.isColumnGroup() } } } } diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt index 44b4520c2c..2674e6c5bd 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt @@ -283,7 +283,7 @@ public fun AnyFrame.toStaticHtml( val id = "static_df_${nextTableId()}" // Retrieve all columns, including nested ones - val flattenedCols = getColumnsWithPaths { colsAtAnyDepth { !it.isColumnGroup() } } + val flattenedCols = getColumnsWithPaths { colsAtAnyDepth().filter { !it.isColumnGroup() } } // Get a grid of columns for the header, as well as the side borders for each cell val colGrid = getColumnsHeaderGrid() diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/allExcept.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/allExcept.kt index 4f9735d4c1..aefb0d43e9 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/allExcept.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/allExcept.kt @@ -149,8 +149,8 @@ class AllExceptTests : ColumnsSelectionDslTests() { listOf( df.select { name.firstName }, - df.select { name.allCols() except { colsAtAnyDepth { "last" in it.name } } }, - df.select { name.allCols() except colsAtAnyDepth { "last" in it.name } }, + df.select { name.allCols() except { colsAtAnyDepth().filter { "last" in it.name } } }, + df.select { name.allCols() except colsAtAnyDepth().filter { "last" in it.name } }, df.select { name.allCols() except { name.lastName } }, df.select { name.allCols() except name.lastName }, df.select { name.allCols() except { colGroup("name").col("lastName") } }, diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/colsAtAnyDepth.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/colsAtAnyDepth.kt index 88b33f551d..0c584b0c98 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/colsAtAnyDepth.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/colsAtAnyDepth.kt @@ -55,21 +55,21 @@ class AtAnyDepth : TestBase() { dfGroup.select { name.firstName.firstName }, dfGroup.select { first { col -> col.any { it == "Alice" } }.atAnyDepthImpl() }, dfGroup.select { colsAtAnyDepth().first { col -> col.any { it == "Alice" } } }, - dfGroup.select { colsAtAnyDepth { col -> col.any { it == "Alice" } }.first() }, + dfGroup.select { colsAtAnyDepth().filter { col -> col.any { it == "Alice" } }.first() }, dfGroup.select { colsAtAnyDepth().last { col -> col.any { it == "Alice" } } }, - dfGroup.select { colsAtAnyDepth { col -> col.any { it == "Alice" } }.last() }, - dfGroup.select { colsAtAnyDepth().single { col -> col.any { it == "Alice" } } }, - dfGroup.select { colsAtAnyDepth { col -> col.any { it == "Alice" } }.single() }, + dfGroup.select { colsAtAnyDepth().filter { col -> col.any { it == "Alice" } }.last() }, + dfGroup.select { colsAtAnyDepth().filter { col -> col.any { it == "Alice" } }.single() }, + dfGroup.select { colsAtAnyDepth().filter { col -> col.any { it == "Alice" } }.single() }, ).shouldAllBeEqual() listOf( dfGroup.select { city }, dfGroup.select { colsAtAnyDepth().first { col -> col.any { it == "London" } } }, - dfGroup.select { colsAtAnyDepth { col -> col.any { it == "London" } }.first() }, + dfGroup.select { colsAtAnyDepth().filter { col -> col.any { it == "London" } }.first() }, dfGroup.select { colsAtAnyDepth().last { col -> col.any { it == "London" } } }, - dfGroup.select { colsAtAnyDepth { col -> col.any { it == "London" } }.last() }, - dfGroup.select { colsAtAnyDepth().single { col -> col.any { it == "London" } } }, - dfGroup.select { colsAtAnyDepth { col -> col.any { it == "London" } }.single() }, + dfGroup.select { colsAtAnyDepth().filter { col -> col.any { it == "London" } }.last() }, + dfGroup.select { colsAtAnyDepth().filter { col -> col.any { it == "London" } }.single() }, + dfGroup.select { colsAtAnyDepth().filter { col -> col.any { it == "London" } }.single() }, ).shouldAllBeEqual() } @@ -78,7 +78,7 @@ class AtAnyDepth : TestBase() { listOf( df.select { name }, df.select { colsAtAnyDepth().colGroups() }, - df.select { colsAtAnyDepth { it.kind == Group } }, + df.select { colsAtAnyDepth().filter { it.kind == Group } }, df.select { colGroups() }, df.select { all().colGroups() }, df.select { all().colsAtAnyDepth().colGroups() }, @@ -111,7 +111,7 @@ class AtAnyDepth : TestBase() { fun `all allAtAnyDepth`() { dfGroup.getColumnsWithPaths { all().colsAtAnyDepth().all() }.sortedBy { it.name } shouldBe atAnyDepthGoal dfGroup - .getColumnsWithPaths { all().colsAtAnyDepth { !it.isColumnGroup() } } + .getColumnsWithPaths { all().colsAtAnyDepth().filter { !it.isColumnGroup() } } .sortedBy { it.name } shouldBe atAnyDepthNoGroups } @@ -119,7 +119,7 @@ class AtAnyDepth : TestBase() { fun `cols allAtAnyDepth`() { dfGroup.getColumnsWithPaths { cols().colsAtAnyDepth().all() }.sortedBy { it.name } shouldBe atAnyDepthGoal dfGroup - .getColumnsWithPaths { cols().colsAtAnyDepth { !it.isColumnGroup() } } + .getColumnsWithPaths { cols().colsAtAnyDepth().filter { !it.isColumnGroup() } } .sortedBy { it.name } shouldBe atAnyDepthNoGroups } diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/move.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/move.kt index f78d83ead7..45edbe5bf8 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/move.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/move.kt @@ -30,7 +30,7 @@ class MoveTests { @Test fun `select all atAnyDepth`() { val selected = grouped - .getColumnsWithPaths { colGroups().colsAtAnyDepth { !it.isColumnGroup() } } + .getColumnsWithPaths { colGroups().colsAtAnyDepth().filter { !it.isColumnGroup() } } .map { it.path.joinToString(".") } selected shouldBe listOf("a.b", "a.c.d", "b.c", "b.d", "e.f") } @@ -38,7 +38,7 @@ class MoveTests { @Test fun `batch ungrouping`() { val ungrouped = grouped.move { - colsAtAnyDepth { it.depth() > 0 && !it.isColumnGroup() } + colsAtAnyDepth().filter { it.depth() > 0 && !it.isColumnGroup() } }.into { pathOf(it.path.joinToString(".")) } ungrouped.columnNames() shouldBe listOf("q", "a.b", "a.c.d", "b.c", "b.d", "w", "e.f", "r") } @@ -71,7 +71,7 @@ class MoveTests { @Test fun `select recursively`() { val selected = grouped.select { - it["a"].asColumnGroup().colsAtAnyDepth { !it.isColumnGroup() } + it["a"].asColumnGroup().colsAtAnyDepth().filter { !it.isColumnGroup() } } selected.columnNames() shouldBe listOf("b", "d") } @@ -80,7 +80,7 @@ class MoveTests { fun `columnsWithPath in selector`() { val selected = grouped.getColumnsWithPaths { it["a"] } val actual = grouped.getColumnsWithPaths { - selected.map { it.asColumnGroup().colsAtAnyDepth { !it.isColumnGroup() } }.toColumnSet() + selected.map { it.asColumnGroup().colsAtAnyDepth().filter { !it.isColumnGroup() } }.toColumnSet() } actual.map { it.path.joinToString(".") } shouldBe listOf("a.b", "a.c.d") } @@ -114,7 +114,7 @@ class MoveTests { @Test fun `move after with column selector`() { - val df = grouped.move { colsAtAnyDepth { it.name == "r" || it.name == "w" } } + val df = grouped.move { colsAtAnyDepth().filter { it.name == "r" || it.name == "w" } } .after { "a"["c"]["d"] } df.columnNames() shouldBe listOf("q", "a", "b", "e") df["a"]["c"].asColumnGroup().columnNames() shouldBe listOf("d", "w", "r") diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/pivot.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/pivot.kt index c85d05e797..cb9b54f184 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/pivot.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/pivot.kt @@ -43,7 +43,7 @@ class PivotTests { } pivoted.columnsCount() shouldBe 3 pivoted.rowsCount() shouldBe 2 - val cols = pivoted.getColumns { allExcept(a).colsAtAnyDepth { !it.isColumnGroup() } } + val cols = pivoted.getColumns { allExcept(a).colsAtAnyDepth().filter { !it.isColumnGroup() } } cols.size shouldBe 4 cols.forEach { it.type() shouldBe typeOf() diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/single.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/single.kt index 9fbb91e151..53ded40b73 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/single.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/single.kt @@ -19,10 +19,10 @@ class SingleTests : ColumnsSelectionDslTests() { df.select { Person::age.singleCol() } } shouldThrow { - df.select { single { false } } + df.select { cols().filter { false }.single() } } shouldThrow { - df.select { single { true } } + df.select { cols().filter { true }.single() } } val singleDf = df.select { take(1) } @@ -32,12 +32,12 @@ class SingleTests : ColumnsSelectionDslTests() { singleDf.select { name }, singleDf.select { single() }, singleDf.select { all().single() }, - df.select { single { it.name().startsWith("n") } }, + df.select { cols().filter { it.name().startsWith("n") }.single() }, ).shouldAllBeEqual() listOf( df.select { name.firstName }, - df.select { name.colsOf().single { col -> col.any { it == "Alice" } } }, + df.select { name.colsOf().filter { col -> col.any { it == "Alice" } }.single() }, df.select { name.singleCol { col -> col.any { it == "Alice" } } }, df.select { "name".singleCol { col -> col.any { it == "Alice" } } }, df.select { Person::name.singleCol { col -> col.any { it == "Alice" } } }, diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/io/PlaylistJsonTest.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/io/PlaylistJsonTest.kt index 3c53afc800..665ff99883 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/io/PlaylistJsonTest.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/io/PlaylistJsonTest.kt @@ -138,7 +138,7 @@ class PlaylistJsonTest { @Test fun `deep batch update all`() { val updated = item - .convert { colsAtAnyDepth { it.name() == "url" } } + .convert { colsAtAnyDepth().filter { it.name() == "url" } } .with { (it as? String)?.let { IMG(it) } } updated.snippet.thumbnails.default.url.type() shouldBe typeOf() updated.snippet.thumbnails.maxres.url.type() shouldBe typeOf() diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/Access.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/Access.kt index 35eff4f495..01fca24d5e 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/Access.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/Access.kt @@ -793,7 +793,7 @@ class Access : TestBase() { df.select { name.allCols() } // traversal of columns at any depth from here excluding ColumnGroups - df.select { name.colsAtAnyDepth { !it.isColumnGroup() } } + df.select { name.colsAtAnyDepth().filter { !it.isColumnGroup() } } // SampleEnd } @@ -831,7 +831,7 @@ class Access : TestBase() { df.select { name.allCols() } // traversal of columns at any depth from here excluding ColumnGroups - df.select { name.colsAtAnyDepth { !it.isColumnGroup() } } + df.select { name.colsAtAnyDepth().filter { !it.isColumnGroup() } } // SampleEnd } @@ -900,7 +900,7 @@ class Access : TestBase() { df.select { "name".allCols() } // traversal of columns at any depth from here excluding ColumnGroups - df.select { "name".colsAtAnyDepth { !it.isColumnGroup() } } + df.select { "name".colsAtAnyDepth().filter { !it.isColumnGroup() } } // SampleEnd } @@ -959,13 +959,13 @@ class Access : TestBase() { } // traversal of columns at any depth from here excluding ColumnGroups - df.select { colsAtAnyDepth { !it.isColumnGroup() } } + df.select { colsAtAnyDepth().filter { !it.isColumnGroup() } } // traversal of columns at any depth from here including ColumnGroups df.select { colsAtAnyDepth() } // traversal of columns at any depth with condition - df.select { colsAtAnyDepth { it.name().contains(":") } } + df.select { colsAtAnyDepth().filter { it.name().contains(":") } } // traversal of columns at any depth to find columns of given type df.select { colsAtAnyDepth().colsOf() } @@ -983,18 +983,18 @@ class Access : TestBase() { fun columnSelectorsModifySet() { // SampleStart // first/last n value- and frame columns in column set - df.select { colsAtAnyDepth { !it.isColumnGroup() }.take(3) } - df.select { colsAtAnyDepth { !it.isColumnGroup() }.takeLast(3) } + df.select { colsAtAnyDepth().filter { !it.isColumnGroup() }.take(3) } + df.select { colsAtAnyDepth().filter { !it.isColumnGroup() }.takeLast(3) } // all except first/last n value- and frame columns in column set - df.select { colsAtAnyDepth { !it.isColumnGroup() }.drop(3) } - df.select { colsAtAnyDepth { !it.isColumnGroup() }.dropLast(3) } + df.select { colsAtAnyDepth().filter { !it.isColumnGroup() }.drop(3) } + df.select { colsAtAnyDepth().filter { !it.isColumnGroup() }.dropLast(3) } // filter column set by condition - df.select { colsAtAnyDepth { !it.isColumnGroup() }.filter { it.name().startsWith("year") } } + df.select { colsAtAnyDepth().filter { !it.isColumnGroup() }.filter { it.name().startsWith("year") } } // exclude columns from column set - df.select { colsAtAnyDepth { !it.isColumnGroup() }.except { age } } + df.select { colsAtAnyDepth().filter { !it.isColumnGroup() }.except { age } } // keep only unique columns df.select { (colsOf() and age).distinct() } diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/DataFrameTests.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/DataFrameTests.kt index 5a4ea0d43c..7da8ba02b2 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/DataFrameTests.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/DataFrameTests.kt @@ -932,7 +932,7 @@ class DataFrameTests : BaseTest() { df["e"].kind() shouldBe ColumnKind.Group df.getColumnGroup("d").columnNames() shouldBe listOf("f") df.getColumnGroup("e").getColumnGroup("g").columnNames() shouldBe listOf("h") - val cols = df.getColumns { colsAtAnyDepth { !it.isColumnGroup() } } + val cols = df.getColumns { colsAtAnyDepth().filter { !it.isColumnGroup() } } cols.size shouldBe 5 cols.forEach { it.toList() shouldBe expected diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/DataFrameTreeTests.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/DataFrameTreeTests.kt index 38a185722b..f20f43269d 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/DataFrameTreeTests.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/DataFrameTreeTests.kt @@ -288,7 +288,7 @@ class DataFrameTreeTests : BaseTest() { @Test fun `select atAnyDepth`() { - val cols = typed2.select { colsAtAnyDepth { it.hasNulls } } + val cols = typed2.select { colsAtAnyDepth().filter { it.hasNulls } } cols shouldBe typed2.select { nameAndCity.city and weight } } @@ -535,14 +535,16 @@ class DataFrameTreeTests : BaseTest() { @Test fun parentColumnTest() { - val res = typed2.move { colsAtAnyDepth { it.depth > 0 } }.toTop { it.parentName + "-" + it.name } + val res = typed2.move { colsAtAnyDepth().filter { it.depth > 0 } }.toTop { it.parentName + "-" + it.name } res.columnsCount() shouldBe 4 res.columnNames() shouldBe listOf("nameAndCity-name", "nameAndCity-city", "age", "weight") } @Test fun `group cols`() { - val joined = typed2.move { colsAtAnyDepth { !it.isColumnGroup() } }.into { pathOf(it.path.joinToString(".")) } + val joined = typed2.move { + colsAtAnyDepth().filter { !it.isColumnGroup() } + }.into { pathOf(it.path.joinToString(".")) } val grouped = joined.group { nameContains(".") }.into { it.name().substringBefore(".") } val expected = typed2.rename { nameAndCity.allCols() }.into { it.path.joinToString(".") } grouped shouldBe expected diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/PivotTests.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/PivotTests.kt index 84be5b6027..d8dd136982 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/PivotTests.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/PivotTests.kt @@ -283,7 +283,7 @@ class PivotTests { val leafColumns = pivoted.getColumnsWithPaths { all() .drop(1) - .colsAtAnyDepth { !it.isColumnGroup() } + .colsAtAnyDepth().filter { !it.isColumnGroup() } } leafColumns.size shouldBe typed.name.countDistinct() * typed.key.countDistinct() - 1 leafColumns.forEach { it.path.size shouldBe 2 } @@ -344,7 +344,7 @@ class PivotTests { // nullGroup.columnTypes() shouldBe listOf(typeOf?>(), typeOf?>()) nullGroup.columnTypes() shouldBe listOf(nothingType(true), nothingType(true)) - val cols = pivotedDf.getColumnsWithPaths { colsAtAnyDepth { !it.isColumnGroup() } } + val cols = pivotedDf.getColumnsWithPaths { colsAtAnyDepth().filter { !it.isColumnGroup() } } cols.size shouldBe 2 * typed.name.countDistinct() * typed.key.countDistinct() - 2 cols.forEach { diff --git a/examples/idea-examples/titanic/src/main/kotlin/org/jetbrains/kotlinx/dataframe/examples/titanic/ml/titanic.kt b/examples/idea-examples/titanic/src/main/kotlin/org/jetbrains/kotlinx/dataframe/examples/titanic/ml/titanic.kt index 685c2520a6..19520bca36 100644 --- a/examples/idea-examples/titanic/src/main/kotlin/org/jetbrains/kotlinx/dataframe/examples/titanic/ml/titanic.kt +++ b/examples/idea-examples/titanic/src/main/kotlin/org/jetbrains/kotlinx/dataframe/examples/titanic/ml/titanic.kt @@ -82,7 +82,7 @@ private fun OnHeapDataset.Companion.create( fun extractX(): Array = dataframe.remove(yColumn) - .convert { colsAtAnyDepth { !it.isColumnGroup() } }.toFloat() + .convert { colsAtAnyDepth().filter { !it.isColumnGroup() } }.toFloat() .merge { colsAtAnyDepth().colsOf() }.by { it.toFloatArray() }.into("X") .getColumn("X").cast().toTypedArray()