From 863a592a54cebbab40d581f74ceec4426076f905 Mon Sep 17 00:00:00 2001 From: Aleksandr Nikolaev Date: Mon, 10 Aug 2026 19:37:12 +0200 Subject: [PATCH 1/8] Fix `drop` and `take` docs --- .../jetbrains/kotlinx/dataframe/api/drop.kt | 134 +++++++++++++++++- .../jetbrains/kotlinx/dataframe/api/take.kt | 105 +++++++++++++- .../documentation/CommonTakeAndDropDocs.kt | 11 +- .../CommonTakeAndDropWhileDocs.kt | 18 ++- docs/StardustDocs/topics/drop.md | 3 + 5 files changed, 256 insertions(+), 15 deletions(-) diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/drop.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/drop.kt index a3608dda38..9d61cd77a0 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/drop.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/drop.kt @@ -1,6 +1,5 @@ package org.jetbrains.kotlinx.dataframe.api -import org.jetbrains.kotlinx.dataframe.ColumnFilter import org.jetbrains.kotlinx.dataframe.DataColumn import org.jetbrains.kotlinx.dataframe.DataFrame import org.jetbrains.kotlinx.dataframe.DataRow @@ -16,6 +15,8 @@ import org.jetbrains.kotlinx.dataframe.columns.size import org.jetbrains.kotlinx.dataframe.documentation.CommonTakeAndDropDocs import org.jetbrains.kotlinx.dataframe.documentation.CommonTakeAndDropWhileDocs import org.jetbrains.kotlinx.dataframe.documentation.DocumentationUrls +import org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns +import org.jetbrains.kotlinx.dataframe.documentation.SelectingRows import org.jetbrains.kotlinx.dataframe.documentation.TakeAndDropColumnsSelectionDslGrammar import org.jetbrains.kotlinx.dataframe.impl.columns.transform import org.jetbrains.kotlinx.dataframe.impl.columns.transformSingle @@ -25,8 +26,37 @@ import kotlin.reflect.KProperty // region DataColumn +/** + * Returns a [DataColumn] containing only the values that do not match the given [predicate]. + * + * For more information: {@include [DocumentationUrls.Drop]} + * + * See also: + * - [filter][DataColumn.filter] — keeps only the values that match the predicate. + * - [drop][DataColumn.drop]`(n: Int)` — drops a fixed number of first values. + * - [dropLast][DataColumn.dropLast] — drops a fixed number of last values. + * + * @param [predicate] The condition used to exclude values from this [DataColumn]. + * @return A [DataColumn] containing the values that do not match the [predicate]. + */ public inline fun DataColumn.drop(predicate: Predicate): DataColumn = filter { !predicate(it) } +/** + * Returns a [DataColumn] containing all values of this [DataColumn] except the first [n] values. + * + * If [n] is greater than or equal to the size of this [DataColumn], an empty [DataColumn] is returned. + * + * See also: + * - [dropLast][DataColumn.dropLast] — drops the last [n] values instead. + * - [take][DataColumn.take] — keeps only the first [n] values. + * - [takeLast][DataColumn.takeLast] — keeps only the last [n] values. + * - [drop][DataColumn.drop]`{ predicate: Predicate }` — drops every value that matches the predicate. + * + * @param [n] The number of values to drop. Must not be negative. + * @return A [DataColumn] containing all values of this [DataColumn] except the first [n], + * or an empty [DataColumn] if [n] is greater than or equal to its size. + * @throws [IndexOutOfBoundsException] if [n] is negative. + */ public fun DataColumn.drop(n: Int): DataColumn = when { n == 0 -> this @@ -34,6 +64,22 @@ public fun DataColumn.drop(n: Int): DataColumn = else -> get(n until size) } +/** + * Returns a [DataColumn] containing all values of this [DataColumn] except the last [n] values. + * + * If [n] is zero or negative, this [DataColumn] is returned as is. + * + * See also: + * - [drop][DataColumn.drop]`(n: Int)` — drops the first [n] values instead. + * - [takeLast][DataColumn.takeLast] — keeps only the last [n] values. + * - [take][DataColumn.take] — keeps only the first [n] values. + * - [drop][DataColumn.drop]`{ predicate: Predicate }` — drops every value that matches the predicate. + * + * @param [n] The number of values to drop. Must not exceed the size of this [DataColumn]. + * @return A [DataColumn] containing all values of this [DataColumn] except the last [n], + * or this [DataColumn] if [n] is zero or negative. + * @throws [IllegalArgumentException] if [n] is greater than the size of this [DataColumn]. + */ public fun DataColumn.dropLast(n: Int = 1): DataColumn = take(size - n) // endregion @@ -41,10 +87,21 @@ public fun DataColumn.dropLast(n: Int = 1): DataColumn = take(size - n // region DataFrame /** - * Returns a DataFrame containing all rows except first [n] rows. + * Returns a [DataFrame] containing all rows except the first [n] rows. + * + * If [n] is greater than or equal to the number of rows, an empty [DataFrame] is returned. * * For more information: {@include [DocumentationUrls.DropFirst]} * + * See also: + * - [dropLast][DataFrame.dropLast] — drops the last [n] rows instead. + * - [dropWhile][DataFrame.dropWhile] — drops the first rows while the predicate holds. + * - [take][DataFrame.take] — keeps only the first [n] rows. + * - [drop][DataFrame.drop]`{ predicate: RowFilter }` — drops every row that matches the predicate. + * + * @param [n] The number of rows to drop. Must not be negative. + * @return A [DataFrame] containing all rows except the first [n], + * or an empty [DataFrame] if [n] is greater than or equal to the number of rows. * @throws IllegalArgumentException if [n] is negative. */ public fun DataFrame.drop(n: Int): DataFrame { @@ -53,10 +110,21 @@ public fun DataFrame.drop(n: Int): DataFrame { } /** - * Returns a DataFrame containing all rows except last [n] rows. + * Returns a [DataFrame] containing all rows except the last [n] rows. + * + * If [n] is greater than or equal to the number of rows, an empty [DataFrame] is returned. * * For more information: {@include [DocumentationUrls.DropLast]} * + * See also: + * - [drop][DataFrame.drop]`(n: Int)` — drops the first [n] rows instead. + * - [dropWhile][DataFrame.dropWhile] — drops the first rows while the predicate holds. + * - [takeLast][DataFrame.takeLast] — keeps only the last [n] rows. + * - [drop][DataFrame.drop]`{ predicate: RowFilter }` — drops every row that matches the predicate. + * + * @param [n] The number of rows to drop. Must not be negative. + * @return A [DataFrame] containing all rows except the last [n], + * or an empty [DataFrame] if [n] is greater than or equal to the number of rows. * @throws IllegalArgumentException if [n] is negative. */ public fun DataFrame.dropLast(n: Int = 1): DataFrame { @@ -65,16 +133,44 @@ public fun DataFrame.dropLast(n: Int = 1): DataFrame { } /** - * Returns a DataFrame containing all rows except rows that satisfy the given [predicate]. + * Returns a [DataFrame] containing all rows except the rows that satisfy the given [predicate]. * - * For more information: {@include [DocumentationUrls.Drop]} + * @include [SelectingRows.RowFilterSnippet] + * + * @include [SelectingColumns.ColumnGroupsAndNestedColumnsSnippet] + * + * {@include [DocumentationUrls.Drop]} + * + * See also: + * - [filter][DataFrame.filter] — keeps only the rows that match the predicate. + * - [dropWhile][DataFrame.dropWhile] — drops only the first rows that match the predicate. + * - [drop][DataFrame.drop]`(n: Int)` — drops a fixed number of first rows. + * + * @param [predicate] The [RowFilter] used to exclude rows from this [DataFrame]. + * @return A [DataFrame] containing all rows that do not satisfy the [predicate]. */ public inline fun DataFrame.drop(predicate: RowFilter): DataFrame = filter { !predicate(it, it) } /** - * Returns a DataFrame containing all rows except first rows that satisfy the given [predicate]. + * Returns a [DataFrame] containing all rows except the first rows that satisfy the given [predicate]. + * + * Rows are dropped for as long as the [predicate] holds; the operation stops at the first row that + * does not satisfy it, and no later row is dropped even if it satisfies the [predicate]. + * + * @include [SelectingRows.RowFilterSnippet] + * + * @include [SelectingColumns.ColumnGroupsAndNestedColumnsSnippet] * * For more information: {@include [DocumentationUrls.DropWhile]} + * + * See also: + * - [drop][DataFrame.drop]`(n: Int)` — drops a fixed number of first rows. + * - [dropLast][DataFrame.dropLast] — drops a fixed number of last rows. + * - [takeWhile][DataFrame.takeWhile] — keeps the first rows while the predicate holds. + * - [drop][DataFrame.drop]`{ predicate: RowFilter }` — drops every row that matches the predicate. + * + * @param [predicate] The [RowFilter] that the leading rows to drop must satisfy. + * @return A [DataFrame] containing all rows except the first ones that satisfy the [predicate]. */ public inline fun DataFrame.dropWhile(predicate: RowFilter): DataFrame = firstOrNull { !predicate(it, it) }?.let { drop(it.index()) } ?: this @@ -125,6 +221,12 @@ public interface DropColumnsSelectionDsl { * @set [CommonTakeAndDropDocs.OPERATION] drop * @set [CommonTakeAndDropDocs.NOUN] drop * @set [CommonTakeAndDropDocs.FIRST_OR_LAST] first + * @set [CommonTakeAndDropDocs.SEE_ALSO] + * - [dropLast][ColumnsSelectionDsl.dropLast] — drops the last `n` columns instead. + * - [dropWhile][ColumnsSelectionDsl.dropWhile] — drops the first columns while a predicate holds. + * - [dropLastWhile][ColumnsSelectionDsl.dropLastWhile] — drops the last columns while a predicate holds. + * - [take][ColumnsSelectionDsl.take] — keeps only the first `n` columns. + * @set [CommonTakeAndDropDocs.RETURN] A [ColumnSet] containing all columns except the first [n\]. */ private typealias CommonDropFirstDocs = Nothing @@ -195,6 +297,12 @@ public interface DropColumnsSelectionDsl { * @set [CommonTakeAndDropDocs.OPERATION] dropLast * @set [CommonTakeAndDropDocs.NOUN] drop * @set [CommonTakeAndDropDocs.FIRST_OR_LAST] last + * @set [CommonTakeAndDropDocs.SEE_ALSO] + * - [drop][ColumnsSelectionDsl.drop] — drops the first `n` columns instead. + * - [dropWhile][ColumnsSelectionDsl.dropWhile] — drops the first columns while a predicate holds. + * - [dropLastWhile][ColumnsSelectionDsl.dropLastWhile] — drops the last columns while a predicate holds. + * - [takeLast][ColumnsSelectionDsl.takeLast] — keeps only the last `n` columns. + * @set [CommonTakeAndDropDocs.RETURN] A [ColumnSet] containing all columns except the last [n\]. */ private typealias CommonDropLastDocs = Nothing @@ -265,6 +373,13 @@ public interface DropColumnsSelectionDsl { * @set [CommonTakeAndDropWhileDocs.OPERATION] drop * @set [CommonTakeAndDropWhileDocs.NOUN] drop * @set [CommonTakeAndDropWhileDocs.FIRST_OR_LAST] first + * @set [CommonTakeAndDropWhileDocs.SEE_ALSO] + * - [drop][ColumnsSelectionDsl.drop] — drops a fixed number of first columns. + * - [dropLast][ColumnsSelectionDsl.dropLast] — drops a fixed number of last columns. + * - [dropLastWhile][ColumnsSelectionDsl.dropLastWhile] — drops the last columns while a predicate holds. + * - [takeWhile][ColumnsSelectionDsl.takeWhile] — keeps the first columns while a predicate holds. + * @set [CommonTakeAndDropWhileDocs.RETURN] A [ColumnSet] containing all columns except the first + * ones adhering to the [predicate\]. */ private typealias CommonDropWhileDocs = Nothing @@ -337,6 +452,13 @@ public interface DropColumnsSelectionDsl { * @set [CommonTakeAndDropWhileDocs.OPERATION] dropLast * @set [CommonTakeAndDropWhileDocs.NOUN] drop * @set [CommonTakeAndDropWhileDocs.FIRST_OR_LAST] last + * @set [CommonTakeAndDropWhileDocs.SEE_ALSO] + * - [drop][ColumnsSelectionDsl.drop] — drops a fixed number of first columns. + * - [dropLast][ColumnsSelectionDsl.dropLast] — drops a fixed number of last columns. + * - [dropWhile][ColumnsSelectionDsl.dropWhile] — drops the first columns while a predicate holds. + * - [takeLastWhile][ColumnsSelectionDsl.takeLastWhile] — keeps the last columns while a predicate holds. + * @set [CommonTakeAndDropWhileDocs.RETURN] A [ColumnSet] containing all columns except the last + * ones adhering to the [predicate\]. */ private typealias CommonDropLastWhileDocs = Nothing diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/take.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/take.kt index a77cab9215..540fb2716e 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/take.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/take.kt @@ -1,6 +1,5 @@ package org.jetbrains.kotlinx.dataframe.api -import org.jetbrains.kotlinx.dataframe.ColumnFilter import org.jetbrains.kotlinx.dataframe.DataColumn import org.jetbrains.kotlinx.dataframe.DataFrame import org.jetbrains.kotlinx.dataframe.DataRow @@ -15,6 +14,8 @@ import org.jetbrains.kotlinx.dataframe.columns.size import org.jetbrains.kotlinx.dataframe.documentation.CommonTakeAndDropDocs import org.jetbrains.kotlinx.dataframe.documentation.CommonTakeAndDropWhileDocs import org.jetbrains.kotlinx.dataframe.documentation.DocumentationUrls +import org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns +import org.jetbrains.kotlinx.dataframe.documentation.SelectingRows import org.jetbrains.kotlinx.dataframe.documentation.TakeAndDropColumnsSelectionDslGrammar import org.jetbrains.kotlinx.dataframe.impl.columns.transform import org.jetbrains.kotlinx.dataframe.impl.columns.transformSingle @@ -24,6 +25,22 @@ import kotlin.reflect.KProperty // region DataColumn +/** + * Returns a [DataColumn] containing the first [n] values of this [DataColumn]. + * + * If [n] is greater than or equal to the size of this [DataColumn], this [DataColumn] is returned as is. + * + * See also: + * - [takeLast][DataColumn.takeLast] — takes the last [n] values instead. + * - [drop][DataColumn.drop]`(n: Int)` — drops the first [n] values. + * - [dropLast][DataColumn.dropLast] — drops the last [n] values. + * - [drop][DataColumn.drop]`{ predicate: Predicate }` — drops every value that matches the predicate. + * + * @param [n] The number of values to take. Must not be negative. + * @return A [DataColumn] containing the first [n] values of this [DataColumn], + * or this [DataColumn] if [n] is greater than or equal to its size. + * @throws [IllegalArgumentException] if [n] is negative. + */ public fun DataColumn.take(n: Int): DataColumn = when { n == 0 -> get(emptyList()) @@ -31,6 +48,22 @@ public fun DataColumn.take(n: Int): DataColumn = else -> get(0 until n) } +/** + * Returns a [DataColumn] containing the last [n] values of this [DataColumn]. + * + * If [n] is zero or negative, an empty [DataColumn] is returned. + * + * See also: + * - [take][DataColumn.take] — takes the first [n] values instead. + * - [dropLast][DataColumn.dropLast] — drops the last [n] values. + * - [drop][DataColumn.drop]`(n: Int)` — drops the first [n] values. + * - [drop][DataColumn.drop]`{ predicate: Predicate }` — drops every value that matches the predicate. + * + * @param [n] The number of values to take. Must not exceed the size of this [DataColumn]. + * @return A [DataColumn] containing the last [n] values of this [DataColumn], + * or an empty [DataColumn] if [n] is zero or negative. + * @throws [IndexOutOfBoundsException] if [n] is greater than the size of this [DataColumn]. + */ public fun DataColumn.takeLast(n: Int = 1): DataColumn = drop(size - n) // endregion @@ -38,10 +71,21 @@ public fun DataColumn.takeLast(n: Int = 1): DataColumn = drop(size - n // region DataFrame /** - * Returns a [DataFrame] containing first [n] rows. + * Returns a [DataFrame] containing the first [n] rows. + * + * If [n] is greater than or equal to the number of rows, the whole [DataFrame] is returned. * * For more information: {@include [DocumentationUrls.TakeFirst]} * + * See also: + * - [takeLast][DataFrame.takeLast] — takes the last [n] rows instead. + * - [takeWhile][DataFrame.takeWhile] — takes the first rows while the predicate holds. + * - [drop][DataFrame.drop]`(n: Int)` — drops the first [n] rows. + * - [filter][DataFrame.filter] — keeps every row that matches the predicate. + * + * @param [n] The number of rows to take. Must not be negative. + * @return A [DataFrame] containing the first [n] rows, + * or the whole [DataFrame] if [n] is greater than or equal to the number of rows. * @throws IllegalArgumentException if [n] is negative. */ public fun DataFrame.take(n: Int): DataFrame { @@ -50,10 +94,21 @@ public fun DataFrame.take(n: Int): DataFrame { } /** - * Returns a [DataFrame] containing last [n] rows. + * Returns a [DataFrame] containing the last [n] rows. + * + * If [n] is greater than or equal to the number of rows, the whole [DataFrame] is returned. * * For more information: {@include [DocumentationUrls.TakeLast]} * + * See also: + * - [take][DataFrame.take] — takes the first [n] rows instead. + * - [takeWhile][DataFrame.takeWhile] — takes the first rows while the predicate holds. + * - [dropLast][DataFrame.dropLast] — drops the last [n] rows. + * - [filter][DataFrame.filter] — keeps every row that matches the predicate. + * + * @param [n] The number of rows to take. Must not be negative. + * @return A [DataFrame] containing the last [n] rows, + * or the whole [DataFrame] if [n] is greater than or equal to the number of rows. * @throws IllegalArgumentException if [n] is negative. */ public fun DataFrame.takeLast(n: Int = 1): DataFrame { @@ -62,9 +117,25 @@ public fun DataFrame.takeLast(n: Int = 1): DataFrame { } /** - * Returns a [DataFrame] containing first rows that satisfy the given [predicate]. + * Returns a [DataFrame] containing the first rows that satisfy the given [predicate]. + * + * Rows are taken for as long as the [predicate] holds; the operation stops at the first row that + * does not satisfy it, and no later row is taken even if it satisfies the [predicate]. + * + * @include [SelectingRows.RowFilterSnippet] + * + * @include [SelectingColumns.ColumnGroupsAndNestedColumnsSnippet] * * For more information: {@include [DocumentationUrls.TakeWhile]} + * + * See also: + * - [take][DataFrame.take] — takes a fixed number of first rows. + * - [takeLast][DataFrame.takeLast] — takes a fixed number of last rows. + * - [dropWhile][DataFrame.dropWhile] — drops the first rows while the predicate holds. + * - [filter][DataFrame.filter] — keeps every row that matches the predicate. + * + * @param [predicate] The [RowFilter] that the leading rows to take must satisfy. + * @return A [DataFrame] containing the first rows that satisfy the [predicate]. */ public inline fun DataFrame.takeWhile(predicate: RowFilter): DataFrame = firstOrNull { !predicate(it, it) }?.let { take(it.index()) } ?: this @@ -115,6 +186,12 @@ public interface TakeColumnsSelectionDsl { * @set [CommonTakeAndDropDocs.OPERATION] take * @set [CommonTakeAndDropDocs.NOUN] take * @set [CommonTakeAndDropDocs.FIRST_OR_LAST] first + * @set [CommonTakeAndDropDocs.SEE_ALSO] + * - [takeLast][ColumnsSelectionDsl.takeLast] — takes the last `n` columns instead. + * - [takeWhile][ColumnsSelectionDsl.takeWhile] — takes the first columns while a predicate holds. + * - [takeLastWhile][ColumnsSelectionDsl.takeLastWhile] — takes the last columns while a predicate holds. + * - [drop][ColumnsSelectionDsl.drop] — drops the first `n` columns. + * @set [CommonTakeAndDropDocs.RETURN] A [ColumnSet] containing the first [n\] columns. */ private typealias CommonTakeFirstDocs = Nothing @@ -187,6 +264,12 @@ public interface TakeColumnsSelectionDsl { * @set [CommonTakeAndDropDocs.OPERATION] takeLast * @set [CommonTakeAndDropDocs.NOUN] take * @set [CommonTakeAndDropDocs.FIRST_OR_LAST] last + * @set [CommonTakeAndDropDocs.SEE_ALSO] + * - [take][ColumnsSelectionDsl.take] — takes the first `n` columns instead. + * - [takeWhile][ColumnsSelectionDsl.takeWhile] — takes the first columns while a predicate holds. + * - [takeLastWhile][ColumnsSelectionDsl.takeLastWhile] — takes the last columns while a predicate holds. + * - [dropLast][ColumnsSelectionDsl.dropLast] — drops the last `n` columns. + * @set [CommonTakeAndDropDocs.RETURN] A [ColumnSet] containing the last [n\] columns. */ private typealias CommonTakeLastDocs = Nothing @@ -259,6 +342,13 @@ public interface TakeColumnsSelectionDsl { * @set [CommonTakeAndDropWhileDocs.OPERATION] take * @set [CommonTakeAndDropWhileDocs.NOUN] take * @set [CommonTakeAndDropWhileDocs.FIRST_OR_LAST] first + * @set [CommonTakeAndDropWhileDocs.SEE_ALSO] + * - [take][ColumnsSelectionDsl.take] — takes a fixed number of first columns. + * - [takeLast][ColumnsSelectionDsl.takeLast] — takes a fixed number of last columns. + * - [takeLastWhile][ColumnsSelectionDsl.takeLastWhile] — takes the last columns while a predicate holds. + * - [dropWhile][ColumnsSelectionDsl.dropWhile] — drops the first columns while a predicate holds. + * @set [CommonTakeAndDropWhileDocs.RETURN] A [ColumnSet] containing the first columns + * adhering to the [predicate\]. */ private typealias CommonTakeFirstWhileDocs = Nothing @@ -333,6 +423,13 @@ public interface TakeColumnsSelectionDsl { * @set [CommonTakeAndDropWhileDocs.OPERATION] takeLast * @set [CommonTakeAndDropWhileDocs.NOUN] take * @set [CommonTakeAndDropWhileDocs.FIRST_OR_LAST] last + * @set [CommonTakeAndDropWhileDocs.SEE_ALSO] + * - [take][ColumnsSelectionDsl.take] — takes a fixed number of first columns. + * - [takeLast][ColumnsSelectionDsl.takeLast] — takes a fixed number of last columns. + * - [takeWhile][ColumnsSelectionDsl.takeWhile] — takes the first columns while a predicate holds. + * - [dropLastWhile][ColumnsSelectionDsl.dropLastWhile] — drops the last columns while a predicate holds. + * @set [CommonTakeAndDropWhileDocs.RETURN] A [ColumnSet] containing the last columns + * adhering to the [predicate\]. */ private typealias CommonTakeLastWhileDocs = Nothing diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/CommonTakeAndDropDocs.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/CommonTakeAndDropDocs.kt index ea8d1f7158..a027eb4895 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/CommonTakeAndDropDocs.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/CommonTakeAndDropDocs.kt @@ -39,8 +39,11 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnSet * * {@get [CommonTakeAndDropDocs.EXAMPLE]} * + * See also: + * {@get [SEE_ALSO]} + * * @param [n\] The number of columns to {@get [NOUN]}. - * @return A [ColumnSet] containing the {@get [FIRST_OR_LAST]} [n\] columns. + * @return {@get [RETURN]} */ internal interface CommonTakeAndDropDocs { @@ -61,4 +64,10 @@ internal interface CommonTakeAndDropDocs { // Link to the corresponding page on the documentation website typealias URL = Nothing + + // Related operations (the `See also` part) + typealias SEE_ALSO = Nothing + + // Value returned by the operation (the `@return` part) + typealias RETURN = Nothing } diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/CommonTakeAndDropWhileDocs.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/CommonTakeAndDropWhileDocs.kt index e0091bc938..d3ea72515e 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/CommonTakeAndDropWhileDocs.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/CommonTakeAndDropWhileDocs.kt @@ -15,8 +15,9 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath /** * ## {@get [TITLE]} (Cols) While - * This function {@get [NOUN]}s the {@get [FIRST_OR_LAST]} columns from [this\] adhering to the - * given [predicate\] collecting the result into a [ColumnSet]. + * This function {@get [NOUN]}s the {@get [FIRST_OR_LAST]} columns from [this\] for as long as the + * given [predicate\] holds, stopping as soon as a column does not adhere to it, and collects the + * result into a [ColumnSet]. * * This function operates solely on columns at the top-level. * @@ -28,7 +29,7 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath * * For more information: {@get [URL]} * - * ### Check out: [Usage\] + * ### Check out: [Grammar\] * * #### Examples: * `df.`[select][DataFrame.select]` { `[`cols`][ColumnsSelectionDsl.cols]` { "my" `[`in`][String.contains]` it.`[`name`][DataColumn.name]` }.`[\`{@get [OPERATION]}While\`][ColumnSet.{@get [OPERATION]}While]` { "my" `[`in`][String.contains]` it.`[`name`][DataColumn.name]` } }` @@ -41,8 +42,11 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath * * {@get [CommonTakeAndDropWhileDocs.EXAMPLE]} * + * See also: + * {@get [SEE_ALSO]} + * * @param [predicate\] The [ColumnFilter] to control which columns to {@get [NOUN]}. - * @return A [ColumnSet] containing the {@get [FIRST_OR_LAST]} columns adhering to the [predicate\]. + * @return {@get [RETURN]} */ internal interface CommonTakeAndDropWhileDocs { @@ -63,4 +67,10 @@ internal interface CommonTakeAndDropWhileDocs { // Link to the corresponding page on the documentation website typealias URL = Nothing + + // Related operations (the `See also` part) + typealias SEE_ALSO = Nothing + + // Value returned by the operation (the `@return` part) + typealias RETURN = Nothing } diff --git a/docs/StardustDocs/topics/drop.md b/docs/StardustDocs/topics/drop.md index 0b1a7a724e..54c82f9bb9 100644 --- a/docs/StardustDocs/topics/drop.md +++ b/docs/StardustDocs/topics/drop.md @@ -25,6 +25,9 @@ df.drop { it["weight"] == null || it["city"] == null } +If called on a [`DataColumn`](DataColumn.md), removes all the values that match the predicate +and returns a [`DataColumn`](DataColumn.md) containing the values that do not match the predicate. + ## dropNulls Remove rows with `null` values. This is a DataFrame equivalent of `filterNotNull`. From 5ae10bb9f06c89b70d64001a7c37d801c620ce25 Mon Sep 17 00:00:00 2001 From: Aleksandr Nikolaev Date: Wed, 19 Aug 2026 13:28:17 +0200 Subject: [PATCH 2/8] Move the samples of the sliceRows operations to the `samples` module --- .../kotlinx/dataframe/samples/api/Access.kt | 66 -- .../api/pivot/pivotInward_properties.html | 2 +- .../sliceRows/drop.html} | 151 +--- .../sliceRows/dropLast1.html} | 151 +--- .../sliceRows/dropLast2.html} | 151 +--- .../sliceRows/dropWhile.html} | 151 +--- .../sliceRows/getSeveralRowsByIndices.html | 516 ++++++++++++++ .../sliceRows/getSeveralRowsByRanges1.html | 516 ++++++++++++++ .../sliceRows/getSeveralRowsByRanges2.html | 516 ++++++++++++++ .../sliceRows/take.html} | 151 +--- .../resources/api/sliceRows/takeLast.html | 516 ++++++++++++++ .../resources/api/sliceRows/takeWhile.html | 516 ++++++++++++++ ...dataframe.samples.api.Access.dropLast.html | 645 ------------------ ...ataframe.samples.api.Access.dropWhile.html | 599 ---------------- ...les.api.Access.getSeveralRowsByRanges.html | 645 ------------------ docs/StardustDocs/topics/_shadow_resources.md | 18 +- docs/StardustDocs/topics/sliceRows.md | 38 +- samples/build.gradle.kts | 1 + .../dataframe/samples/api/SliceRowsSamples.kt | 94 +++ 19 files changed, 2883 insertions(+), 2560 deletions(-) rename docs/StardustDocs/resources/{snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.takeLast.html => api/sliceRows/drop.html} (60%) rename docs/StardustDocs/resources/{snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.drop.html => api/sliceRows/dropLast1.html} (77%) rename docs/StardustDocs/resources/{snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.getSeveralRowsByIndices.html => api/sliceRows/dropLast2.html} (71%) rename docs/StardustDocs/resources/{snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.takeWhile.html => api/sliceRows/dropWhile.html} (77%) create mode 100644 docs/StardustDocs/resources/api/sliceRows/getSeveralRowsByIndices.html create mode 100644 docs/StardustDocs/resources/api/sliceRows/getSeveralRowsByRanges1.html create mode 100644 docs/StardustDocs/resources/api/sliceRows/getSeveralRowsByRanges2.html rename docs/StardustDocs/resources/{snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.take.html => api/sliceRows/take.html} (69%) create mode 100644 docs/StardustDocs/resources/api/sliceRows/takeLast.html create mode 100644 docs/StardustDocs/resources/api/sliceRows/takeWhile.html delete mode 100644 docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropLast.html delete mode 100644 docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropWhile.html delete mode 100644 docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.getSeveralRowsByRanges.html create mode 100644 samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/SliceRowsSamples.kt 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 8e3b16a7ff..0bba87e6f0 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 @@ -216,23 +216,6 @@ class Access : TestBase() { // SampleEnd } - @Test - @TransformDataFrameExpressions - fun getSeveralRowsByIndices() { - // SampleStart - df[0, 3, 4] - // SampleEnd - } - - @Test - @TransformDataFrameExpressions - fun getSeveralRowsByRanges() { - // SampleStart - df[1..2] - df[0..2, 4..5] - // SampleEnd - } - @Test @TransformDataFrameExpressions fun getRowsColumns() { @@ -243,55 +226,6 @@ class Access : TestBase() { // SampleEnd } - @Test - @TransformDataFrameExpressions - fun take() { - // SampleStart - df.take(5) - // SampleEnd - } - - @Test - @TransformDataFrameExpressions - fun takeLast() { - // SampleStart - df.takeLast(5) - // SampleEnd - } - - @Test - @TransformDataFrameExpressions - fun takeWhile() { - // SampleStart - df.takeWhile { isHappy } - // SampleEnd - } - - @Test - @TransformDataFrameExpressions - fun drop() { - // SampleStart - df.drop(5) - // SampleEnd - } - - @Test - @TransformDataFrameExpressions - fun dropLast() { - // SampleStart - df.dropLast() // default 1 - df.dropLast(5) - // SampleEnd - } - - @Test - @TransformDataFrameExpressions - fun dropWhile() { - // SampleStart - df.dropWhile { !isHappy } - // SampleEnd - } - @Test @TransformDataFrameExpressions fun dropWhere_properties() { diff --git a/docs/StardustDocs/resources/api/pivot/pivotInward_properties.html b/docs/StardustDocs/resources/api/pivot/pivotInward_properties.html index 16700b2fb1..4ec0390d05 100644 --- a/docs/StardustDocs/resources/api/pivot/pivotInward_properties.html +++ b/docs/StardustDocs/resources/api/pivot/pivotInward_properties.html @@ -459,7 +459,7 @@ /**/ diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.takeLast.html b/docs/StardustDocs/resources/api/sliceRows/drop.html similarity index 60% rename from docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.takeLast.html rename to docs/StardustDocs/resources/api/sliceRows/drop.html index 9a29078ceb..a3ce43a149 100644 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.takeLast.html +++ b/docs/StardustDocs/resources/api/sliceRows/drop.html @@ -177,18 +177,9 @@ -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
+

-
-
- Output DataFrame: rowsCount = 5, columnsCount = 5 -
- -

-
diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.drop.html b/docs/StardustDocs/resources/api/sliceRows/dropLast1.html similarity index 77% rename from docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.drop.html rename to docs/StardustDocs/resources/api/sliceRows/dropLast1.html index b457727b57..be5cc5c12a 100644 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.drop.html +++ b/docs/StardustDocs/resources/api/sliceRows/dropLast1.html @@ -177,18 +177,9 @@ -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
+

-
-
- Output DataFrame: rowsCount = 2, columnsCount = 5 -
- -

-
diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.getSeveralRowsByIndices.html b/docs/StardustDocs/resources/api/sliceRows/dropLast2.html similarity index 71% rename from docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.getSeveralRowsByIndices.html rename to docs/StardustDocs/resources/api/sliceRows/dropLast2.html index 585856c2fc..8c10513e29 100644 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.getSeveralRowsByIndices.html +++ b/docs/StardustDocs/resources/api/sliceRows/dropLast2.html @@ -177,18 +177,9 @@ -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
+

-
-
- Output DataFrame: rowsCount = 3, columnsCount = 5 -
- -

-
diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.takeWhile.html b/docs/StardustDocs/resources/api/sliceRows/dropWhile.html similarity index 77% rename from docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.takeWhile.html rename to docs/StardustDocs/resources/api/sliceRows/dropWhile.html index 59a5b7f0b6..bf549bf28c 100644 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.takeWhile.html +++ b/docs/StardustDocs/resources/api/sliceRows/dropWhile.html @@ -177,18 +177,9 @@ -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
+

-
-
- Output DataFrame: rowsCount = 2, columnsCount = 5 -
- -

-
diff --git a/docs/StardustDocs/resources/api/sliceRows/getSeveralRowsByIndices.html b/docs/StardustDocs/resources/api/sliceRows/getSeveralRowsByIndices.html new file mode 100644 index 0000000000..f83be5eeee --- /dev/null +++ b/docs/StardustDocs/resources/api/sliceRows/getSeveralRowsByIndices.html @@ -0,0 +1,516 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/sliceRows/getSeveralRowsByRanges1.html b/docs/StardustDocs/resources/api/sliceRows/getSeveralRowsByRanges1.html new file mode 100644 index 0000000000..54669a6293 --- /dev/null +++ b/docs/StardustDocs/resources/api/sliceRows/getSeveralRowsByRanges1.html @@ -0,0 +1,516 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/sliceRows/getSeveralRowsByRanges2.html b/docs/StardustDocs/resources/api/sliceRows/getSeveralRowsByRanges2.html new file mode 100644 index 0000000000..8509db0c20 --- /dev/null +++ b/docs/StardustDocs/resources/api/sliceRows/getSeveralRowsByRanges2.html @@ -0,0 +1,516 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.take.html b/docs/StardustDocs/resources/api/sliceRows/take.html similarity index 69% rename from docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.take.html rename to docs/StardustDocs/resources/api/sliceRows/take.html index 174767c01b..8c10513e29 100644 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.take.html +++ b/docs/StardustDocs/resources/api/sliceRows/take.html @@ -177,18 +177,9 @@ -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
+

-
-
- Output DataFrame: rowsCount = 5, columnsCount = 5 -
- -

-
diff --git a/docs/StardustDocs/resources/api/sliceRows/takeLast.html b/docs/StardustDocs/resources/api/sliceRows/takeLast.html new file mode 100644 index 0000000000..a3ce43a149 --- /dev/null +++ b/docs/StardustDocs/resources/api/sliceRows/takeLast.html @@ -0,0 +1,516 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/sliceRows/takeWhile.html b/docs/StardustDocs/resources/api/sliceRows/takeWhile.html new file mode 100644 index 0000000000..c62f73ec69 --- /dev/null +++ b/docs/StardustDocs/resources/api/sliceRows/takeWhile.html @@ -0,0 +1,516 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropLast.html b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropLast.html deleted file mode 100644 index 8052e7e6d2..0000000000 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropLast.html +++ /dev/null @@ -1,645 +0,0 @@ - - - - - -
- df.dropLast() -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
- Output DataFrame: rowsCount = 6, columnsCount = 5 -
- -

-
-
-
-
- df.dropLast(5) -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
- Output DataFrame: rowsCount = 2, columnsCount = 5 -
- -

-
-
-
- - - diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropWhile.html b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropWhile.html deleted file mode 100644 index cfd98995eb..0000000000 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropWhile.html +++ /dev/null @@ -1,599 +0,0 @@ - - - - - -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
- Output DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
- - - diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.getSeveralRowsByRanges.html b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.getSeveralRowsByRanges.html deleted file mode 100644 index e6926b68c5..0000000000 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.getSeveralRowsByRanges.html +++ /dev/null @@ -1,645 +0,0 @@ - - - - - -
- df.df[1..2] -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
- Output DataFrame: rowsCount = 2, columnsCount = 5 -
- -

-
-
-
-
- df.df[0..2, 4..5] -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
- Output DataFrame: rowsCount = 5, columnsCount = 5 -
- -

-
-
-
- - - diff --git a/docs/StardustDocs/topics/_shadow_resources.md b/docs/StardustDocs/topics/_shadow_resources.md index 08f1ae858a..91c5854b0d 100644 --- a/docs/StardustDocs/topics/_shadow_resources.md +++ b/docs/StardustDocs/topics/_shadow_resources.md @@ -235,23 +235,15 @@ - - - - - - - - @@ -356,3 +348,13 @@ + + + + + + + + + + diff --git a/docs/StardustDocs/topics/sliceRows.md b/docs/StardustDocs/topics/sliceRows.md index 30c51db986..b9fc7fe9dd 100644 --- a/docs/StardustDocs/topics/sliceRows.md +++ b/docs/StardustDocs/topics/sliceRows.md @@ -1,6 +1,6 @@ [//]: # (title: Slice rows) - + Returns a [`DataFrame`](DataFrame.md) with rows at given indices: @@ -10,20 +10,28 @@ Returns a [`DataFrame`](DataFrame.md) with rows at given indices: df[0, 3, 4] ``` - + Returns a [`DataFrame`](DataFrame.md) with rows inside given index ranges (including boundary indices): - + ```kotlin df[1..2] +``` + + + + + + +```kotlin df[0..2, 4..5] ``` - + ## take @@ -35,8 +43,8 @@ Returns a [`DataFrame`](DataFrame.md) containing first `n` rows df.take(5) ``` - + ## takeLast @@ -48,8 +56,8 @@ Returns a [`DataFrame`](DataFrame.md) containing last `n` rows df.takeLast(5) ``` - + ## takeWhile @@ -61,8 +69,8 @@ Returns a [`DataFrame`](DataFrame.md) containing first rows that satisfy the giv df.takeWhile { isHappy } ``` - + ## drop @@ -74,22 +82,30 @@ Returns a [`DataFrame`](DataFrame.md) containing all rows except first `n` rows df.drop(5) ``` - + ## dropLast Returns a [`DataFrame`](DataFrame.md) containing all rows except last `n` rows - + ```kotlin df.dropLast() // default 1 +``` + + + + + + +```kotlin df.dropLast(5) ``` - + ## dropWhile @@ -101,5 +117,5 @@ Returns a [`DataFrame`](DataFrame.md) containing all rows except first rows that df.dropWhile { !isHappy } ``` - + diff --git a/samples/build.gradle.kts b/samples/build.gradle.kts index 200716beb8..df1d0fec77 100644 --- a/samples/build.gradle.kts +++ b/samples/build.gradle.kts @@ -120,6 +120,7 @@ korro { include("filter.md") include("count.md") include("valueCounts.md") + include("sliceRows.md") }, ) baseDir = rootProject.file("docs/StardustDocs/topics") diff --git a/samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/SliceRowsSamples.kt b/samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/SliceRowsSamples.kt new file mode 100644 index 0000000000..a336a78550 --- /dev/null +++ b/samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/SliceRowsSamples.kt @@ -0,0 +1,94 @@ +package org.jetbrains.kotlinx.dataframe.samples.api + +import org.jetbrains.kotlinx.dataframe.api.drop +import org.jetbrains.kotlinx.dataframe.api.dropLast +import org.jetbrains.kotlinx.dataframe.api.dropWhile +import org.jetbrains.kotlinx.dataframe.api.take +import org.jetbrains.kotlinx.dataframe.api.takeLast +import org.jetbrains.kotlinx.dataframe.api.takeWhile +import org.jetbrains.kotlinx.dataframe.samples.DataFrameSampleHelper +import org.junit.Test + +class SliceRowsSamples: DataFrameSampleHelper("sliceRows", "api") { + val df = peopleDf + + @Test + fun getSeveralRowsByIndices() { + // SampleStart + df[0, 3, 4] + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun getSeveralRowsByRanges1() { + // SampleStart + df[1..2] + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun getSeveralRowsByRanges2() { + // SampleStart + df[0..2, 4..5] + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun take() { + // SampleStart + df.take(5) + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun takeLast() { + // SampleStart + df.takeLast(5) + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun takeWhile() { + // SampleStart + df.takeWhile { isHappy } + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun drop() { + // SampleStart + df.drop(5) + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun dropLast1() { + // SampleStart + df.dropLast() // default 1 + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun dropLast2() { + // SampleStart + df.dropLast(5) + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun dropWhile() { + // SampleStart + df.dropWhile { !isHappy } + // SampleEnd + .saveDfHtmlSample() + } +} From 14632b60c3fff5930dd03ee79d8076123da08930 Mon Sep 17 00:00:00 2001 From: Aleksandr Nikolaev Date: Wed, 19 Aug 2026 14:30:55 +0200 Subject: [PATCH 3/8] Add to KDocs of DataColumn overloads of `take` and `drop` the links to the website --- .../main/kotlin/org/jetbrains/kotlinx/dataframe/api/drop.kt | 4 ++++ .../main/kotlin/org/jetbrains/kotlinx/dataframe/api/take.kt | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/drop.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/drop.kt index 9d61cd77a0..447784adb4 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/drop.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/drop.kt @@ -46,6 +46,8 @@ public inline fun DataColumn.drop(predicate: Predicate): DataColumn * * If [n] is greater than or equal to the size of this [DataColumn], an empty [DataColumn] is returned. * + * For more information: {@include [DocumentationUrls.DropFirst]} + * * See also: * - [dropLast][DataColumn.dropLast] — drops the last [n] values instead. * - [take][DataColumn.take] — keeps only the first [n] values. @@ -69,6 +71,8 @@ public fun DataColumn.drop(n: Int): DataColumn = * * If [n] is zero or negative, this [DataColumn] is returned as is. * + * For more information: {@include [DocumentationUrls.DropLast]} + * * See also: * - [drop][DataColumn.drop]`(n: Int)` — drops the first [n] values instead. * - [takeLast][DataColumn.takeLast] — keeps only the last [n] values. diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/take.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/take.kt index 540fb2716e..997a41bb14 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/take.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/take.kt @@ -30,6 +30,8 @@ import kotlin.reflect.KProperty * * If [n] is greater than or equal to the size of this [DataColumn], this [DataColumn] is returned as is. * + * For more information: {@include [DocumentationUrls.TakeFirst]} + * * See also: * - [takeLast][DataColumn.takeLast] — takes the last [n] values instead. * - [drop][DataColumn.drop]`(n: Int)` — drops the first [n] values. @@ -53,6 +55,8 @@ public fun DataColumn.take(n: Int): DataColumn = * * If [n] is zero or negative, an empty [DataColumn] is returned. * + * For more information: {@include [DocumentationUrls.TakeLast]} + * * See also: * - [take][DataColumn.take] — takes the first [n] values instead. * - [dropLast][DataColumn.dropLast] — drops the last [n] values. From b659e155fa0abfefbcd6fd0debfb1fa0acb9b4ac Mon Sep 17 00:00:00 2001 From: Aleksandr Nikolaev Date: Wed, 19 Aug 2026 14:34:44 +0200 Subject: [PATCH 4/8] Add samples for `DataColumn` overloads of `take` and `drop` --- .../api/sliceRows/dropDataColumn.html | 510 ++++++++++++++++++ .../api/sliceRows/dropLastDataColumn.html | 510 ++++++++++++++++++ .../api/sliceRows/takeDataColumn.html | 510 ++++++++++++++++++ .../api/sliceRows/takeLastDataColumn.html | 510 ++++++++++++++++++ docs/StardustDocs/topics/_shadow_resources.md | 4 + docs/StardustDocs/topics/sliceRows.md | 46 ++ .../dataframe/samples/api/SliceRowsSamples.kt | 60 ++- 7 files changed, 2137 insertions(+), 13 deletions(-) create mode 100644 docs/StardustDocs/resources/api/sliceRows/dropDataColumn.html create mode 100644 docs/StardustDocs/resources/api/sliceRows/dropLastDataColumn.html create mode 100644 docs/StardustDocs/resources/api/sliceRows/takeDataColumn.html create mode 100644 docs/StardustDocs/resources/api/sliceRows/takeLastDataColumn.html diff --git a/docs/StardustDocs/resources/api/sliceRows/dropDataColumn.html b/docs/StardustDocs/resources/api/sliceRows/dropDataColumn.html new file mode 100644 index 0000000000..9779822aa0 --- /dev/null +++ b/docs/StardustDocs/resources/api/sliceRows/dropDataColumn.html @@ -0,0 +1,510 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/sliceRows/dropLastDataColumn.html b/docs/StardustDocs/resources/api/sliceRows/dropLastDataColumn.html new file mode 100644 index 0000000000..2e870a32b6 --- /dev/null +++ b/docs/StardustDocs/resources/api/sliceRows/dropLastDataColumn.html @@ -0,0 +1,510 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/sliceRows/takeDataColumn.html b/docs/StardustDocs/resources/api/sliceRows/takeDataColumn.html new file mode 100644 index 0000000000..2e870a32b6 --- /dev/null +++ b/docs/StardustDocs/resources/api/sliceRows/takeDataColumn.html @@ -0,0 +1,510 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/sliceRows/takeLastDataColumn.html b/docs/StardustDocs/resources/api/sliceRows/takeLastDataColumn.html new file mode 100644 index 0000000000..9779822aa0 --- /dev/null +++ b/docs/StardustDocs/resources/api/sliceRows/takeLastDataColumn.html @@ -0,0 +1,510 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/topics/_shadow_resources.md b/docs/StardustDocs/topics/_shadow_resources.md index 91c5854b0d..0daec027a4 100644 --- a/docs/StardustDocs/topics/_shadow_resources.md +++ b/docs/StardustDocs/topics/_shadow_resources.md @@ -358,3 +358,7 @@ + + + + diff --git a/docs/StardustDocs/topics/sliceRows.md b/docs/StardustDocs/topics/sliceRows.md index b9fc7fe9dd..cc5067f653 100644 --- a/docs/StardustDocs/topics/sliceRows.md +++ b/docs/StardustDocs/topics/sliceRows.md @@ -46,6 +46,17 @@ df.take(5) +If called on a [`DataColumn`](DataColumn.md), returns a [`DataColumn`](DataColumn.md) containing its first `n` values. + + + +```kotlin +df.age.take(5) +``` + + + + ## takeLast Returns a [`DataFrame`](DataFrame.md) containing last `n` rows @@ -59,6 +70,17 @@ df.takeLast(5) +If called on a [`DataColumn`](DataColumn.md), returns a [`DataColumn`](DataColumn.md) containing its last `n` values. + + + +```kotlin +df.age.takeLast(5) +``` + + + + ## takeWhile Returns a [`DataFrame`](DataFrame.md) containing first rows that satisfy the given [condition](DataRow.md#row-conditions) @@ -85,6 +107,18 @@ df.drop(5) +If called on a [`DataColumn`](DataColumn.md), returns a [`DataColumn`](DataColumn.md) +containing all values of this [`DataColumn`](DataColumn.md) except the first `n` values. + + + +```kotlin +df.age.drop(5) +``` + + + + ## dropLast Returns a [`DataFrame`](DataFrame.md) containing all rows except last `n` rows @@ -107,6 +141,18 @@ df.dropLast(5) +If called on a [`DataColumn`](DataColumn.md), returns a [`DataColumn`](DataColumn.md) +containing all values of this [`DataColumn`](DataColumn.md) except the last `n` values. + + + +```kotlin +df.age.dropLast(5) +``` + + + + ## dropWhile Returns a [`DataFrame`](DataFrame.md) containing all rows except first rows that satisfy the given [condition](DataRow.md#row-conditions) diff --git a/samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/SliceRowsSamples.kt b/samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/SliceRowsSamples.kt index a336a78550..903b6a038e 100644 --- a/samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/SliceRowsSamples.kt +++ b/samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/SliceRowsSamples.kt @@ -9,14 +9,14 @@ import org.jetbrains.kotlinx.dataframe.api.takeWhile import org.jetbrains.kotlinx.dataframe.samples.DataFrameSampleHelper import org.junit.Test -class SliceRowsSamples: DataFrameSampleHelper("sliceRows", "api") { +class SliceRowsSamples : DataFrameSampleHelper("sliceRows", "api") { val df = peopleDf @Test fun getSeveralRowsByIndices() { // SampleStart df[0, 3, 4] - // SampleEnd + // SampleEnd .saveDfHtmlSample() } @@ -24,7 +24,7 @@ class SliceRowsSamples: DataFrameSampleHelper("sliceRows", "api") { fun getSeveralRowsByRanges1() { // SampleStart df[1..2] - // SampleEnd + // SampleEnd .saveDfHtmlSample() } @@ -32,15 +32,23 @@ class SliceRowsSamples: DataFrameSampleHelper("sliceRows", "api") { fun getSeveralRowsByRanges2() { // SampleStart df[0..2, 4..5] - // SampleEnd - .saveDfHtmlSample() + // SampleEnd + .saveDfHtmlSample() } @Test fun take() { // SampleStart df.take(5) - // SampleEnd + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun takeDataColumn() { + // SampleStart + df.age.take(5) + // SampleEnd .saveDfHtmlSample() } @@ -48,23 +56,39 @@ class SliceRowsSamples: DataFrameSampleHelper("sliceRows", "api") { fun takeLast() { // SampleStart df.takeLast(5) - // SampleEnd - .saveDfHtmlSample() + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun takeLastDataColumn() { + // SampleStart + df.age.takeLast(5) + // SampleEnd + .saveDfHtmlSample() } @Test fun takeWhile() { // SampleStart df.takeWhile { isHappy } - // SampleEnd - .saveDfHtmlSample() + // SampleEnd + .saveDfHtmlSample() } @Test fun drop() { // SampleStart df.drop(5) - // SampleEnd + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun dropDataColumn() { + // SampleStart + df.age.drop(5) + // SampleEnd .saveDfHtmlSample() } @@ -72,8 +96,8 @@ class SliceRowsSamples: DataFrameSampleHelper("sliceRows", "api") { fun dropLast1() { // SampleStart df.dropLast() // default 1 - // SampleEnd - .saveDfHtmlSample() + // SampleEnd + .saveDfHtmlSample() } @Test @@ -84,11 +108,21 @@ class SliceRowsSamples: DataFrameSampleHelper("sliceRows", "api") { .saveDfHtmlSample() } + @Test + fun dropLastDataColumn() { + // SampleStart + df.age.dropLast(5) + // SampleEnd + .saveDfHtmlSample() + } + @Test fun dropWhile() { // SampleStart df.dropWhile { !isHappy } // SampleEnd .saveDfHtmlSample() + // SampleEnd + .saveDfHtmlSample() } } From a548d4039fee39478f5d01be10d55ef6771afce8 Mon Sep 17 00:00:00 2001 From: Aleksandr Nikolaev Date: Wed, 19 Aug 2026 14:36:53 +0200 Subject: [PATCH 5/8] Update the sample for `dropWhile` to make it more illustrative --- .../resources/api/sliceRows/dropWhile.html | 16 ++++++++-------- docs/StardustDocs/topics/sliceRows.md | 2 +- .../dataframe/samples/api/SliceRowsSamples.kt | 4 +--- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/docs/StardustDocs/resources/api/sliceRows/dropWhile.html b/docs/StardustDocs/resources/api/sliceRows/dropWhile.html index bf549bf28c..a998153eb5 100644 --- a/docs/StardustDocs/resources/api/sliceRows/dropWhile.html +++ b/docs/StardustDocs/resources/api/sliceRows/dropWhile.html @@ -457,14 +457,14 @@ })() /**/ call_DataFrame(function() { DataFrame.renderTable(0) }); diff --git a/docs/StardustDocs/topics/sliceRows.md b/docs/StardustDocs/topics/sliceRows.md index cc5067f653..5d2bd21328 100644 --- a/docs/StardustDocs/topics/sliceRows.md +++ b/docs/StardustDocs/topics/sliceRows.md @@ -160,7 +160,7 @@ Returns a [`DataFrame`](DataFrame.md) containing all rows except first rows that ```kotlin -df.dropWhile { !isHappy } +df.dropWhile { isHappy } ``` diff --git a/samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/SliceRowsSamples.kt b/samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/SliceRowsSamples.kt index 903b6a038e..5146b7223b 100644 --- a/samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/SliceRowsSamples.kt +++ b/samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/SliceRowsSamples.kt @@ -119,9 +119,7 @@ class SliceRowsSamples : DataFrameSampleHelper("sliceRows", "api") { @Test fun dropWhile() { // SampleStart - df.dropWhile { !isHappy } - // SampleEnd - .saveDfHtmlSample() + df.dropWhile { isHappy } // SampleEnd .saveDfHtmlSample() } From 2523a2826d78533de71f03fe859f32a3f4d8800f Mon Sep 17 00:00:00 2001 From: Aleksandr Nikolaev Date: Wed, 19 Aug 2026 16:06:25 +0200 Subject: [PATCH 6/8] Move samples for `drop`, `dropNulls`, `dropNaNs`, `dropNA` to the `samples` module --- .../kotlinx/dataframe/samples/api/Access.kt | 52 -- .../resources/api/drop/dropNA.html | 516 ++++++++++++ .../resources/api/drop/dropNASelector.html | 516 ++++++++++++ .../api/drop/dropNASelectorSeveralCols.html | 516 ++++++++++++ .../drop/dropNAWhereAllNA.html} | 151 +--- .../api/drop/dropNAWhereAllNASelector.html | 516 ++++++++++++ .../resources/api/drop/dropNaNs.html | 516 ++++++++++++ .../resources/api/drop/dropNaNsSelector.html | 516 ++++++++++++ .../api/drop/dropNaNsSelectorSeveralCols.html | 516 ++++++++++++ .../api/drop/dropNaNsWhereAllNaN.html | 516 ++++++++++++ .../api/drop/dropNaNsWhereAllNaNSelector.html | 516 ++++++++++++ .../resources/api/drop/dropNulls.html | 516 ++++++++++++ .../resources/api/drop/dropNullsSelector.html | 516 ++++++++++++ .../drop/dropNullsSelectorSeveralCols.html | 516 ++++++++++++ .../api/drop/dropNullsWhereAllNull.html | 516 ++++++++++++ .../drop/dropNullsWhereAllNullSelector.html | 516 ++++++++++++ .../api/drop/dropWhere_properties.html | 516 ++++++++++++ .../api/pivot/pivotInward_properties.html | 2 +- ...x.dataframe.samples.api.Access.dropNA.html | 771 ------------------ ...dataframe.samples.api.Access.dropNaNs.html | 771 ------------------ ...ataframe.samples.api.Access.dropNulls.html | 771 ------------------ docs/StardustDocs/topics/_shadow_resources.md | 20 +- docs/StardustDocs/topics/drop.md | 106 ++- samples/build.gradle.kts | 1 + .../dataframe/samples/api/DropNullsNansNa.kt | 147 ++++ 25 files changed, 8040 insertions(+), 2492 deletions(-) create mode 100644 docs/StardustDocs/resources/api/drop/dropNA.html create mode 100644 docs/StardustDocs/resources/api/drop/dropNASelector.html create mode 100644 docs/StardustDocs/resources/api/drop/dropNASelectorSeveralCols.html rename docs/StardustDocs/resources/{snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropWhere.html => api/drop/dropNAWhereAllNA.html} (74%) create mode 100644 docs/StardustDocs/resources/api/drop/dropNAWhereAllNASelector.html create mode 100644 docs/StardustDocs/resources/api/drop/dropNaNs.html create mode 100644 docs/StardustDocs/resources/api/drop/dropNaNsSelector.html create mode 100644 docs/StardustDocs/resources/api/drop/dropNaNsSelectorSeveralCols.html create mode 100644 docs/StardustDocs/resources/api/drop/dropNaNsWhereAllNaN.html create mode 100644 docs/StardustDocs/resources/api/drop/dropNaNsWhereAllNaNSelector.html create mode 100644 docs/StardustDocs/resources/api/drop/dropNulls.html create mode 100644 docs/StardustDocs/resources/api/drop/dropNullsSelector.html create mode 100644 docs/StardustDocs/resources/api/drop/dropNullsSelectorSeveralCols.html create mode 100644 docs/StardustDocs/resources/api/drop/dropNullsWhereAllNull.html create mode 100644 docs/StardustDocs/resources/api/drop/dropNullsWhereAllNullSelector.html create mode 100644 docs/StardustDocs/resources/api/drop/dropWhere_properties.html delete mode 100644 docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropNA.html delete mode 100644 docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropNaNs.html delete mode 100644 docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropNulls.html create mode 100644 samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/DropNullsNansNa.kt 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 0bba87e6f0..7b3e0cf5b3 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 @@ -226,58 +226,6 @@ class Access : TestBase() { // SampleEnd } - @Test - @TransformDataFrameExpressions - fun dropWhere_properties() { - // SampleStart - df.drop { weight == null || city == null } - // SampleEnd - } - - @Test - @TransformDataFrameExpressions - fun dropWhere_strings() { - // SampleStart - df.drop { it["weight"] == null || it["city"] == null } - // SampleEnd - } - - @Test - @TransformDataFrameExpressions - fun dropNulls() { - // SampleStart - df.dropNulls() // remove rows with null value in any column - df.dropNulls(whereAllNull = true) // remove rows with null values in all columns - df.dropNulls { city } // remove rows with null value in 'city' column - df.dropNulls { city and weight } // remove rows with null value in 'city' OR 'weight' columns - df.dropNulls(whereAllNull = true) { city and weight } // remove rows with null value in 'city' AND 'weight' columns - // SampleEnd - } - - @Test - @TransformDataFrameExpressions - fun dropNaNs() { - // SampleStart - df.dropNaNs() // remove rows containing NaN in any column - df.dropNaNs(whereAllNaN = true) // remove rows with NaN in all columns - df.dropNaNs { weight } // remove rows where 'weight' is NaN - df.dropNaNs { age and weight } // remove rows where either 'age' or 'weight' is NaN - df.dropNaNs(whereAllNaN = true) { age and weight } // remove rows where both 'age' and 'weight' are NaN - // SampleEnd - } - - @Test - @TransformDataFrameExpressions - fun dropNA() { - // SampleStart - df.dropNA() // remove rows containing null or NaN in any column - df.dropNA(whereAllNA = true) // remove rows with null or NaN in all columns - df.dropNA { weight } // remove rows where 'weight' is null or NaN - df.dropNA { age and weight } // remove rows where either 'age' or 'weight' is null or NaN - df.dropNA(whereAllNA = true) { age and weight } // remove rows where both 'age' and 'weight' are null or NaN - // SampleEnd - } - @Test @TransformDataFrameExpressions fun byColumn_strings() { diff --git a/docs/StardustDocs/resources/api/drop/dropNA.html b/docs/StardustDocs/resources/api/drop/dropNA.html new file mode 100644 index 0000000000..fa066e9fdd --- /dev/null +++ b/docs/StardustDocs/resources/api/drop/dropNA.html @@ -0,0 +1,516 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/drop/dropNASelector.html b/docs/StardustDocs/resources/api/drop/dropNASelector.html new file mode 100644 index 0000000000..173e20b4bf --- /dev/null +++ b/docs/StardustDocs/resources/api/drop/dropNASelector.html @@ -0,0 +1,516 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/drop/dropNASelectorSeveralCols.html b/docs/StardustDocs/resources/api/drop/dropNASelectorSeveralCols.html new file mode 100644 index 0000000000..173e20b4bf --- /dev/null +++ b/docs/StardustDocs/resources/api/drop/dropNASelectorSeveralCols.html @@ -0,0 +1,516 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropWhere.html b/docs/StardustDocs/resources/api/drop/dropNAWhereAllNA.html similarity index 74% rename from docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropWhere.html rename to docs/StardustDocs/resources/api/drop/dropNAWhereAllNA.html index 0d0e5f1364..bf549bf28c 100644 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropWhere.html +++ b/docs/StardustDocs/resources/api/drop/dropNAWhereAllNA.html @@ -177,18 +177,9 @@ -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
+

-
-
- Output DataFrame: rowsCount = 4, columnsCount = 5 -
- -

-
diff --git a/docs/StardustDocs/resources/api/drop/dropNAWhereAllNASelector.html b/docs/StardustDocs/resources/api/drop/dropNAWhereAllNASelector.html new file mode 100644 index 0000000000..bf549bf28c --- /dev/null +++ b/docs/StardustDocs/resources/api/drop/dropNAWhereAllNASelector.html @@ -0,0 +1,516 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/drop/dropNaNs.html b/docs/StardustDocs/resources/api/drop/dropNaNs.html new file mode 100644 index 0000000000..bf549bf28c --- /dev/null +++ b/docs/StardustDocs/resources/api/drop/dropNaNs.html @@ -0,0 +1,516 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/drop/dropNaNsSelector.html b/docs/StardustDocs/resources/api/drop/dropNaNsSelector.html new file mode 100644 index 0000000000..bf549bf28c --- /dev/null +++ b/docs/StardustDocs/resources/api/drop/dropNaNsSelector.html @@ -0,0 +1,516 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/drop/dropNaNsSelectorSeveralCols.html b/docs/StardustDocs/resources/api/drop/dropNaNsSelectorSeveralCols.html new file mode 100644 index 0000000000..bf549bf28c --- /dev/null +++ b/docs/StardustDocs/resources/api/drop/dropNaNsSelectorSeveralCols.html @@ -0,0 +1,516 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/drop/dropNaNsWhereAllNaN.html b/docs/StardustDocs/resources/api/drop/dropNaNsWhereAllNaN.html new file mode 100644 index 0000000000..bf549bf28c --- /dev/null +++ b/docs/StardustDocs/resources/api/drop/dropNaNsWhereAllNaN.html @@ -0,0 +1,516 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/drop/dropNaNsWhereAllNaNSelector.html b/docs/StardustDocs/resources/api/drop/dropNaNsWhereAllNaNSelector.html new file mode 100644 index 0000000000..bf549bf28c --- /dev/null +++ b/docs/StardustDocs/resources/api/drop/dropNaNsWhereAllNaNSelector.html @@ -0,0 +1,516 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/drop/dropNulls.html b/docs/StardustDocs/resources/api/drop/dropNulls.html new file mode 100644 index 0000000000..fa066e9fdd --- /dev/null +++ b/docs/StardustDocs/resources/api/drop/dropNulls.html @@ -0,0 +1,516 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/drop/dropNullsSelector.html b/docs/StardustDocs/resources/api/drop/dropNullsSelector.html new file mode 100644 index 0000000000..cdfc07baf5 --- /dev/null +++ b/docs/StardustDocs/resources/api/drop/dropNullsSelector.html @@ -0,0 +1,516 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/drop/dropNullsSelectorSeveralCols.html b/docs/StardustDocs/resources/api/drop/dropNullsSelectorSeveralCols.html new file mode 100644 index 0000000000..fa066e9fdd --- /dev/null +++ b/docs/StardustDocs/resources/api/drop/dropNullsSelectorSeveralCols.html @@ -0,0 +1,516 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/drop/dropNullsWhereAllNull.html b/docs/StardustDocs/resources/api/drop/dropNullsWhereAllNull.html new file mode 100644 index 0000000000..bf549bf28c --- /dev/null +++ b/docs/StardustDocs/resources/api/drop/dropNullsWhereAllNull.html @@ -0,0 +1,516 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/drop/dropNullsWhereAllNullSelector.html b/docs/StardustDocs/resources/api/drop/dropNullsWhereAllNullSelector.html new file mode 100644 index 0000000000..bf549bf28c --- /dev/null +++ b/docs/StardustDocs/resources/api/drop/dropNullsWhereAllNullSelector.html @@ -0,0 +1,516 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/drop/dropWhere_properties.html b/docs/StardustDocs/resources/api/drop/dropWhere_properties.html new file mode 100644 index 0000000000..fa066e9fdd --- /dev/null +++ b/docs/StardustDocs/resources/api/drop/dropWhere_properties.html @@ -0,0 +1,516 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/pivot/pivotInward_properties.html b/docs/StardustDocs/resources/api/pivot/pivotInward_properties.html index 4ec0390d05..0e568d1566 100644 --- a/docs/StardustDocs/resources/api/pivot/pivotInward_properties.html +++ b/docs/StardustDocs/resources/api/pivot/pivotInward_properties.html @@ -459,7 +459,7 @@ /**/ diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropNA.html b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropNA.html deleted file mode 100644 index c8fca9bb08..0000000000 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropNA.html +++ /dev/null @@ -1,771 +0,0 @@ - - - - - -
- df.dropNA() -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
- Output DataFrame: rowsCount = 4, columnsCount = 5 -
- -

-
-
-
-
- df.dropNA(whereAllNA = true) -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
- Output DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
-
-
- df.dropNA { weight } -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
- Output DataFrame: rowsCount = 5, columnsCount = 5 -
- -

-
-
-
-
- df.dropNA { age and weight } -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
- Output DataFrame: rowsCount = 5, columnsCount = 5 -
- -

-
-
-
-
- df.dropNA(whereAllNA = true) { age and weight } -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
- Output DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
-
- - - diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropNaNs.html b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropNaNs.html deleted file mode 100644 index 81d6ee3ba7..0000000000 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropNaNs.html +++ /dev/null @@ -1,771 +0,0 @@ - - - - - -
- df.dropNaNs() -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
- Output DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
-
-
- df.dropNaNs(whereAllNaN = true) -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
- Output DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
-
-
- df.dropNaNs { weight } -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
- Output DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
-
-
- df.dropNaNs { age and weight } -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
- Output DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
-
-
- df.dropNaNs(whereAllNaN = true) { age and weight } -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
- Output DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
-
- - - diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropNulls.html b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropNulls.html deleted file mode 100644 index 6c77b5225f..0000000000 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.dropNulls.html +++ /dev/null @@ -1,771 +0,0 @@ - - - - - -
- df.dropNulls() -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
- Output DataFrame: rowsCount = 4, columnsCount = 5 -
- -

-
-
-
-
- df.dropNulls(whereAllNull = true) -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
- Output DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
-
-
- df.dropNulls { city } -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
- Output DataFrame: rowsCount = 6, columnsCount = 5 -
- -

-
-
-
-
- df.dropNulls { city and weight } -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
- Output DataFrame: rowsCount = 4, columnsCount = 5 -
- -

-
-
-
-
- df.dropNulls(whereAllNull = true) { city and weight } -
- Input DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
- Output DataFrame: rowsCount = 7, columnsCount = 5 -
- -

-
-
-
- - - diff --git a/docs/StardustDocs/topics/_shadow_resources.md b/docs/StardustDocs/topics/_shadow_resources.md index 0daec027a4..02416154a6 100644 --- a/docs/StardustDocs/topics/_shadow_resources.md +++ b/docs/StardustDocs/topics/_shadow_resources.md @@ -235,10 +235,6 @@ - - - - @@ -362,3 +358,19 @@ + + + + + + + + + + + + + + + + diff --git a/docs/StardustDocs/topics/drop.md b/docs/StardustDocs/topics/drop.md index 54c82f9bb9..77776f54ec 100644 --- a/docs/StardustDocs/topics/drop.md +++ b/docs/StardustDocs/topics/drop.md @@ -1,6 +1,6 @@ [//]: # (title: drop / dropNulls / dropNaNs / dropNA) - + Removes all rows that satisfy [row condition](DataRow.md#row-conditions) @@ -22,8 +22,8 @@ df.drop { it["weight"] == null || it["city"] == null } ``` - + If called on a [`DataColumn`](DataColumn.md), removes all the values that match the predicate and returns a [`DataColumn`](DataColumn.md) containing the values that do not match the predicate. @@ -38,14 +38,46 @@ See [column selectors](ColumnSelectors.md) for how to select the columns for thi ```kotlin df.dropNulls() // remove rows with null value in any column +``` + + + + + + +```kotlin df.dropNulls(whereAllNull = true) // remove rows with null values in all columns +``` + + + + + + +```kotlin df.dropNulls { city } // remove rows with null value in 'city' column +``` + + + + + + +```kotlin df.dropNulls { city and weight } // remove rows with null value in 'city' OR 'weight' columns +``` + + + + + + +```kotlin df.dropNulls(whereAllNull = true) { city and weight } // remove rows with null value in 'city' AND 'weight' columns ``` - + If called on a [`DataColumn`](DataColumn.md), removes `null` values from this [`DataColumn`](DataColumn.md), adjusting the type accordingly. @@ -60,14 +92,46 @@ See [column selectors](ColumnSelectors.md) for how to select the columns for thi ```kotlin df.dropNaNs() // remove rows containing NaN in any column +``` + + + + + + +```kotlin df.dropNaNs(whereAllNaN = true) // remove rows with NaN in all columns +``` + + + + + + +```kotlin df.dropNaNs { weight } // remove rows where 'weight' is NaN +``` + + + + + + +```kotlin df.dropNaNs { age and weight } // remove rows where either 'age' or 'weight' is NaN +``` + + + + + + +```kotlin df.dropNaNs(whereAllNaN = true) { age and weight } // remove rows where both 'age' and 'weight' are NaN ``` - + If called on a [`DataColumn`](DataColumn.md), removes [`NaN` values](nanAndNa.md#nan) from this [`DataColumn`](DataColumn.md), adjusting the type accordingly. @@ -82,14 +146,46 @@ See [column selectors](ColumnSelectors.md) for how to select the columns for thi ```kotlin df.dropNA() // remove rows containing null or NaN in any column +``` + + + + + + +```kotlin df.dropNA(whereAllNA = true) // remove rows with null or NaN in all columns +``` + + + + + + +```kotlin df.dropNA { weight } // remove rows where 'weight' is null or NaN +``` + + + + + + +```kotlin df.dropNA { age and weight } // remove rows where either 'age' or 'weight' is null or NaN +``` + + + + + + +```kotlin df.dropNA(whereAllNA = true) { age and weight } // remove rows where both 'age' and 'weight' are null or NaN ``` - + If called on a [`DataColumn`](DataColumn.md), removes [`NA` values](nanAndNa.md#na) from this [`DataColumn`](DataColumn.md), adjusting the type accordingly. diff --git a/samples/build.gradle.kts b/samples/build.gradle.kts index df1d0fec77..bfdd29e300 100644 --- a/samples/build.gradle.kts +++ b/samples/build.gradle.kts @@ -117,6 +117,7 @@ korro { include("groupBy.md") include("pivot.md") include("countDistinct.md") + include("drop.md") include("filter.md") include("count.md") include("valueCounts.md") diff --git a/samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/DropNullsNansNa.kt b/samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/DropNullsNansNa.kt new file mode 100644 index 0000000000..3c3246f12d --- /dev/null +++ b/samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/DropNullsNansNa.kt @@ -0,0 +1,147 @@ +package org.jetbrains.kotlinx.dataframe.samples.api + +import org.jetbrains.kotlinx.dataframe.api.drop +import org.jetbrains.kotlinx.dataframe.api.dropNA +import org.jetbrains.kotlinx.dataframe.api.dropNaNs +import org.jetbrains.kotlinx.dataframe.api.dropNulls +import org.jetbrains.kotlinx.dataframe.samples.DataFrameSampleHelper +import org.junit.Test + +class DropNullsNansNa : DataFrameSampleHelper("drop", "api") { + val df = peopleDf + + @Test + fun dropWhere_properties() { + // SampleStart + df.drop { weight == null || city == null } + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun dropWhere_strings() { + // SampleStart + df.drop { it["weight"] == null || it["city"] == null } + // SampleEnd + } + + @Test + fun dropNulls() { + // SampleStart + df.dropNulls() // remove rows with null value in any column + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun dropNullsWhereAllNull() { + // SampleStart + df.dropNulls(whereAllNull = true) // remove rows with null values in all columns + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun dropNullsSelector() { + // SampleStart + df.dropNulls { city } // remove rows with null value in 'city' column + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun dropNullsSelectorSeveralCols() { + // SampleStart + df.dropNulls { city and weight } // remove rows with null value in 'city' OR 'weight' columns + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun dropNullsWhereAllNullSelector() { + // SampleStart + df.dropNulls(whereAllNull = true) { city and weight } // remove rows with null value in 'city' AND 'weight' columns + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun dropNaNs() { + // SampleStart + df.dropNaNs() // remove rows containing NaN in any column + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun dropNaNsWhereAllNaN() { + // SampleStart + df.dropNaNs(whereAllNaN = true) // remove rows with NaN in all columns + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun dropNaNsSelector() { + // SampleStart + df.dropNaNs { weight } // remove rows where 'weight' is NaN + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun dropNaNsSelectorSeveralCols() { + // SampleStart + df.dropNaNs { age and weight } // remove rows where either 'age' or 'weight' is NaN + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun dropNaNsWhereAllNaNSelector() { + // SampleStart + df.dropNaNs(whereAllNaN = true) { age and weight } // remove rows where both 'age' and 'weight' are NaN + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun dropNA() { + // SampleStart + df.dropNA() // remove rows containing null or NaN in any column + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun dropNAWhereAllNA() { + // SampleStart + df.dropNA(whereAllNA = true) // remove rows with null or NaN in all columns + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun dropNASelector() { + // SampleStart + df.dropNA { weight } // remove rows where 'weight' is null or NaN + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun dropNASelectorSeveralCols() { + // SampleStart + df.dropNA { age and weight } // remove rows where either 'age' or 'weight' is null or NaN + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun dropNAWhereAllNASelector() { + // SampleStart + df.dropNA(whereAllNA = true) { age and weight } // remove rows where both 'age' and 'weight' are null or NaN + // SampleEnd + .saveDfHtmlSample() + } +} From 5235110e54a5798eebc34ee9de2a0ef28ea58490 Mon Sep 17 00:00:00 2001 From: Aleksandr Nikolaev Date: Wed, 19 Aug 2026 16:26:13 +0200 Subject: [PATCH 7/8] Add samples for `DataColumn` overloads of `drop`, `dropNulls`, `dropNaNs`, `dropNA` --- .../api/drop/dropDataColumnByPredicate.html | 510 +++++++++++++++++ .../resources/api/drop/dropDf.html | 516 ++++++++++++++++++ .../resources/api/drop/dropNADataColumn.html | 510 +++++++++++++++++ .../api/drop/dropNaNsDataColumn.html | 510 +++++++++++++++++ .../api/drop/dropNullsDataColumn.html | 510 +++++++++++++++++ .../api/pivot/pivotInward_properties.html | 2 +- docs/StardustDocs/topics/_shadow_resources.md | 5 + docs/StardustDocs/topics/drop.md | 54 +- ...llsNansNa.kt => DropNullsNansNaSamples.kt} | 103 +++- 9 files changed, 2687 insertions(+), 33 deletions(-) create mode 100644 docs/StardustDocs/resources/api/drop/dropDataColumnByPredicate.html create mode 100644 docs/StardustDocs/resources/api/drop/dropDf.html create mode 100644 docs/StardustDocs/resources/api/drop/dropNADataColumn.html create mode 100644 docs/StardustDocs/resources/api/drop/dropNaNsDataColumn.html create mode 100644 docs/StardustDocs/resources/api/drop/dropNullsDataColumn.html rename samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/{DropNullsNansNa.kt => DropNullsNansNaSamples.kt} (63%) diff --git a/docs/StardustDocs/resources/api/drop/dropDataColumnByPredicate.html b/docs/StardustDocs/resources/api/drop/dropDataColumnByPredicate.html new file mode 100644 index 0000000000..ba10c542e9 --- /dev/null +++ b/docs/StardustDocs/resources/api/drop/dropDataColumnByPredicate.html @@ -0,0 +1,510 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/drop/dropDf.html b/docs/StardustDocs/resources/api/drop/dropDf.html new file mode 100644 index 0000000000..bf549bf28c --- /dev/null +++ b/docs/StardustDocs/resources/api/drop/dropDf.html @@ -0,0 +1,516 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/drop/dropNADataColumn.html b/docs/StardustDocs/resources/api/drop/dropNADataColumn.html new file mode 100644 index 0000000000..5c0b88a4b7 --- /dev/null +++ b/docs/StardustDocs/resources/api/drop/dropNADataColumn.html @@ -0,0 +1,510 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/drop/dropNaNsDataColumn.html b/docs/StardustDocs/resources/api/drop/dropNaNsDataColumn.html new file mode 100644 index 0000000000..5c0b88a4b7 --- /dev/null +++ b/docs/StardustDocs/resources/api/drop/dropNaNsDataColumn.html @@ -0,0 +1,510 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/drop/dropNullsDataColumn.html b/docs/StardustDocs/resources/api/drop/dropNullsDataColumn.html new file mode 100644 index 0000000000..b9d7e2bcee --- /dev/null +++ b/docs/StardustDocs/resources/api/drop/dropNullsDataColumn.html @@ -0,0 +1,510 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/resources/api/pivot/pivotInward_properties.html b/docs/StardustDocs/resources/api/pivot/pivotInward_properties.html index 0e568d1566..b583c64ca7 100644 --- a/docs/StardustDocs/resources/api/pivot/pivotInward_properties.html +++ b/docs/StardustDocs/resources/api/pivot/pivotInward_properties.html @@ -459,7 +459,7 @@ /**/ diff --git a/docs/StardustDocs/topics/_shadow_resources.md b/docs/StardustDocs/topics/_shadow_resources.md index 02416154a6..064370fa23 100644 --- a/docs/StardustDocs/topics/_shadow_resources.md +++ b/docs/StardustDocs/topics/_shadow_resources.md @@ -364,13 +364,18 @@ + + + + + diff --git a/docs/StardustDocs/topics/drop.md b/docs/StardustDocs/topics/drop.md index 77776f54ec..3c412228c0 100644 --- a/docs/StardustDocs/topics/drop.md +++ b/docs/StardustDocs/topics/drop.md @@ -1,6 +1,18 @@ [//]: # (title: drop / dropNulls / dropNaNs / dropNA) - + + +The examples on this page use the following dataframe: + + +```kotlin +df +``` + + + + +## drop Removes all rows that satisfy [row condition](DataRow.md#row-conditions) @@ -28,6 +40,15 @@ df.drop { it["weight"] == null || it["city"] == null } If called on a [`DataColumn`](DataColumn.md), removes all the values that match the predicate and returns a [`DataColumn`](DataColumn.md) containing the values that do not match the predicate. + + +```kotlin +df.age.drop { it < 20 } +``` + + + + ## dropNulls Remove rows with `null` values. This is a DataFrame equivalent of `filterNotNull`. @@ -73,7 +94,7 @@ df.dropNulls { city and weight } // remove rows with null value in 'city' OR 'we ```kotlin -df.dropNulls(whereAllNull = true) { city and weight } // remove rows with null value in 'city' AND 'weight' columns +df.dropNulls(whereAllNull = true) { city and weight } // remove rows with nulls in both columns ``` @@ -82,6 +103,15 @@ df.dropNulls(whereAllNull = true) { city and weight } // remove rows with null v If called on a [`DataColumn`](DataColumn.md), removes `null` values from this [`DataColumn`](DataColumn.md), adjusting the type accordingly. + + +```kotlin +df.weight.dropNulls() +``` + + + + ## dropNaNs Remove rows with [`NaN` values](nanAndNa.md#nan) (`Double.NaN` or `Float.NaN`). @@ -136,6 +166,16 @@ df.dropNaNs(whereAllNaN = true) { age and weight } // remove rows where both 'ag If called on a [`DataColumn`](DataColumn.md), removes [`NaN` values](nanAndNa.md#nan) from this [`DataColumn`](DataColumn.md), adjusting the type accordingly. + + +```kotlin +val values by columnOf(1.0, Double.NaN, 2.0, Double.NaN) +values.dropNaNs() +``` + + + + ## dropNA Remove rows with [`NA` values](nanAndNa.md#na) (`null`, `Double.NaN`, or `Float.NaN`). @@ -189,3 +229,13 @@ df.dropNA(whereAllNA = true) { age and weight } // remove rows where both 'age' If called on a [`DataColumn`](DataColumn.md), removes [`NA` values](nanAndNa.md#na) from this [`DataColumn`](DataColumn.md), adjusting the type accordingly. + + + +```kotlin +val values by columnOf(1.0, null, Double.NaN, 2.0) +values.dropNA() +``` + + + diff --git a/samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/DropNullsNansNa.kt b/samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/DropNullsNansNaSamples.kt similarity index 63% rename from samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/DropNullsNansNa.kt rename to samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/DropNullsNansNaSamples.kt index 3c3246f12d..05ff483c02 100644 --- a/samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/DropNullsNansNa.kt +++ b/samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/DropNullsNansNaSamples.kt @@ -1,5 +1,6 @@ package org.jetbrains.kotlinx.dataframe.samples.api +import org.jetbrains.kotlinx.dataframe.api.columnOf import org.jetbrains.kotlinx.dataframe.api.drop import org.jetbrains.kotlinx.dataframe.api.dropNA import org.jetbrains.kotlinx.dataframe.api.dropNaNs @@ -7,14 +8,22 @@ import org.jetbrains.kotlinx.dataframe.api.dropNulls import org.jetbrains.kotlinx.dataframe.samples.DataFrameSampleHelper import org.junit.Test -class DropNullsNansNa : DataFrameSampleHelper("drop", "api") { +class DropNullsNansNaSamples : DataFrameSampleHelper("drop", "api") { val df = peopleDf + @Test + fun dropDf() { + // SampleStart + df + // SampleEnd + .saveDfHtmlSample() + } + @Test fun dropWhere_properties() { // SampleStart df.drop { weight == null || city == null } - // SampleEnd + // SampleEnd .saveDfHtmlSample() } @@ -25,11 +34,19 @@ class DropNullsNansNa : DataFrameSampleHelper("drop", "api") { // SampleEnd } + @Test + fun dropDataColumnByPredicate() { + // SampleStart + df.age.drop { it < 20 } + // SampleEnd + .saveDfHtmlSample() + } + @Test fun dropNulls() { // SampleStart df.dropNulls() // remove rows with null value in any column - // SampleEnd + // SampleEnd .saveDfHtmlSample() } @@ -37,7 +54,7 @@ class DropNullsNansNa : DataFrameSampleHelper("drop", "api") { fun dropNullsWhereAllNull() { // SampleStart df.dropNulls(whereAllNull = true) // remove rows with null values in all columns - // SampleEnd + // SampleEnd .saveDfHtmlSample() } @@ -45,7 +62,7 @@ class DropNullsNansNa : DataFrameSampleHelper("drop", "api") { fun dropNullsSelector() { // SampleStart df.dropNulls { city } // remove rows with null value in 'city' column - // SampleEnd + // SampleEnd .saveDfHtmlSample() } @@ -53,95 +70,121 @@ class DropNullsNansNa : DataFrameSampleHelper("drop", "api") { fun dropNullsSelectorSeveralCols() { // SampleStart df.dropNulls { city and weight } // remove rows with null value in 'city' OR 'weight' columns - // SampleEnd - .saveDfHtmlSample() + // SampleEnd + .saveDfHtmlSample() } @Test fun dropNullsWhereAllNullSelector() { // SampleStart - df.dropNulls(whereAllNull = true) { city and weight } // remove rows with null value in 'city' AND 'weight' columns - // SampleEnd - .saveDfHtmlSample() + df.dropNulls(whereAllNull = true) { city and weight } // remove rows with nulls in both columns + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun dropNullsDataColumn() { + // SampleStart + df.weight.dropNulls() + // SampleEnd + .saveDfHtmlSample() } @Test fun dropNaNs() { // SampleStart df.dropNaNs() // remove rows containing NaN in any column - // SampleEnd - .saveDfHtmlSample() + // SampleEnd + .saveDfHtmlSample() } @Test fun dropNaNsWhereAllNaN() { // SampleStart df.dropNaNs(whereAllNaN = true) // remove rows with NaN in all columns - // SampleEnd - .saveDfHtmlSample() + // SampleEnd + .saveDfHtmlSample() } @Test fun dropNaNsSelector() { // SampleStart df.dropNaNs { weight } // remove rows where 'weight' is NaN - // SampleEnd - .saveDfHtmlSample() + // SampleEnd + .saveDfHtmlSample() } @Test fun dropNaNsSelectorSeveralCols() { // SampleStart df.dropNaNs { age and weight } // remove rows where either 'age' or 'weight' is NaN - // SampleEnd - .saveDfHtmlSample() + // SampleEnd + .saveDfHtmlSample() } @Test fun dropNaNsWhereAllNaNSelector() { // SampleStart df.dropNaNs(whereAllNaN = true) { age and weight } // remove rows where both 'age' and 'weight' are NaN - // SampleEnd - .saveDfHtmlSample() + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun dropNaNsDataColumn() { + // SampleStart + val values by columnOf(1.0, Double.NaN, 2.0, Double.NaN) + values.dropNaNs() + // SampleEnd + .saveDfHtmlSample() } @Test fun dropNA() { // SampleStart df.dropNA() // remove rows containing null or NaN in any column - // SampleEnd - .saveDfHtmlSample() + // SampleEnd + .saveDfHtmlSample() } @Test fun dropNAWhereAllNA() { // SampleStart df.dropNA(whereAllNA = true) // remove rows with null or NaN in all columns - // SampleEnd - .saveDfHtmlSample() + // SampleEnd + .saveDfHtmlSample() } @Test fun dropNASelector() { // SampleStart df.dropNA { weight } // remove rows where 'weight' is null or NaN - // SampleEnd - .saveDfHtmlSample() + // SampleEnd + .saveDfHtmlSample() } @Test fun dropNASelectorSeveralCols() { // SampleStart df.dropNA { age and weight } // remove rows where either 'age' or 'weight' is null or NaN - // SampleEnd - .saveDfHtmlSample() + // SampleEnd + .saveDfHtmlSample() } @Test fun dropNAWhereAllNASelector() { // SampleStart df.dropNA(whereAllNA = true) { age and weight } // remove rows where both 'age' and 'weight' are null or NaN - // SampleEnd - .saveDfHtmlSample() + // SampleEnd + .saveDfHtmlSample() + } + + @Test + fun dropNADataColumn() { + // SampleStart + val values by columnOf(1.0, null, Double.NaN, 2.0) + values.dropNA() + // SampleEnd + .saveDfHtmlSample() } } From c8eb9d793bcb5a5cee777af6443f2dde803fb5a8 Mon Sep 17 00:00:00 2001 From: Aleksandr Nikolaev Date: Wed, 19 Aug 2026 16:30:49 +0200 Subject: [PATCH 8/8] Add a df sample for `sliceRows` operations --- .../api/pivot/pivotInward_properties.html | 2 +- .../resources/api/sliceRows/sliceRowsDf.html | 516 ++++++++++++++++++ docs/StardustDocs/topics/_shadow_resources.md | 1 + docs/StardustDocs/topics/sliceRows.md | 9 + .../dataframe/samples/api/SliceRowsSamples.kt | 8 + 5 files changed, 535 insertions(+), 1 deletion(-) create mode 100644 docs/StardustDocs/resources/api/sliceRows/sliceRowsDf.html diff --git a/docs/StardustDocs/resources/api/pivot/pivotInward_properties.html b/docs/StardustDocs/resources/api/pivot/pivotInward_properties.html index b583c64ca7..3b2bebc20c 100644 --- a/docs/StardustDocs/resources/api/pivot/pivotInward_properties.html +++ b/docs/StardustDocs/resources/api/pivot/pivotInward_properties.html @@ -459,7 +459,7 @@ /**/ diff --git a/docs/StardustDocs/resources/api/sliceRows/sliceRowsDf.html b/docs/StardustDocs/resources/api/sliceRows/sliceRowsDf.html new file mode 100644 index 0000000000..bf549bf28c --- /dev/null +++ b/docs/StardustDocs/resources/api/sliceRows/sliceRowsDf.html @@ -0,0 +1,516 @@ + + + + + +
+ +

+ + + diff --git a/docs/StardustDocs/topics/_shadow_resources.md b/docs/StardustDocs/topics/_shadow_resources.md index 064370fa23..56f55794e3 100644 --- a/docs/StardustDocs/topics/_shadow_resources.md +++ b/docs/StardustDocs/topics/_shadow_resources.md @@ -379,3 +379,4 @@ + diff --git a/docs/StardustDocs/topics/sliceRows.md b/docs/StardustDocs/topics/sliceRows.md index 5d2bd21328..3a98e27c1b 100644 --- a/docs/StardustDocs/topics/sliceRows.md +++ b/docs/StardustDocs/topics/sliceRows.md @@ -4,6 +4,15 @@ Returns a [`DataFrame`](DataFrame.md) with rows at given indices: + + +```kotlin +df +``` + + + + ```kotlin diff --git a/samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/SliceRowsSamples.kt b/samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/SliceRowsSamples.kt index 5146b7223b..e5a384330a 100644 --- a/samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/SliceRowsSamples.kt +++ b/samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/SliceRowsSamples.kt @@ -12,6 +12,14 @@ import org.junit.Test class SliceRowsSamples : DataFrameSampleHelper("sliceRows", "api") { val df = peopleDf + @Test + fun sliceRowsDf() { + // SampleStart + df + // SampleEnd + .saveDfHtmlSample() + } + @Test fun getSeveralRowsByIndices() { // SampleStart