@@ -10,6 +10,9 @@ import org.jetbrains.kotlinx.dataframe.annotations.Refine
1010import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
1111import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
1212import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
13+ import org.jetbrains.kotlinx.dataframe.documentation.DocumentationUrls
14+ import org.jetbrains.kotlinx.dataframe.documentation.ExcludeFromSources
15+ import org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns
1316import org.jetbrains.kotlinx.dataframe.impl.api.explodeImpl
1417import org.jetbrains.kotlinx.dataframe.util.DEPRECATED_ACCESS_API
1518import kotlin.reflect.KProperty
@@ -19,13 +22,82 @@ private val defaultExplodeColumns: ColumnsSelector<*, *> = {
1922}
2023
2124// region explode DataFrame
25+
26+ /* *
27+ * Splits list-like values in the specified [\columns] and spreads them vertically —
28+ * that is, it adds a separate row for each element (one value per row).
29+ * Values in all other columns are duplicated to preserve row context.
30+ *
31+ * If no [\columns] are specified, all columns (at any depth) containing
32+ * [List] or [DataFrame] values will be exploded.
33+ *
34+ * If [dropEmpty] is `true`, rows with empty lists or [DataFrame]s will be removed.
35+ * If `false`, such rows will be exploded into `null` values.
36+ *
37+ * Returns a new [DataFrame] with exploded columns.
38+ *
39+ * Each exploded column will have a new type (`List<T>` -> `T`).
40+ * When several columns are exploded in one operation, lists in different columns will be aligned.
41+ *
42+ * This operation is the reverse of [implode].
43+ *
44+ * @include [SelectingColumns.ColumnGroupsAndNestedColumnsMention]
45+ *
46+ * For more information, see: {@include [DocumentationUrls.Explode]}
47+ *
48+ * ### This `explode` overload
49+ */
50+ @ExcludeFromSources
51+ internal interface ExplodeDocs
52+
53+ /* *
54+ * {@include [ExplodeDocs]}
55+ * {@include [SelectingColumns.Dsl]}
56+ *
57+ * #### Examples
58+ *
59+ * ```kotlin
60+ * // Explodes all `List` and `DataFrame` columns at any depth
61+ * df.explode()
62+ *
63+ * // Explodes the "tags" column of type `List<String>`
64+ * df.explode { tags }
65+ *
66+ * // Explodes all columns of type `List<Double>`
67+ * df.explode { colsOf<List<Double>>() }
68+ * ```
69+ *
70+ * @param dropEmpty If `true`, removes rows with empty lists or DataFrames.
71+ * If `false`, such rows will be exploded into `null` values.
72+ * @param columns The [ColumnsSelector] used to select columns to explode.
73+ * If not specified, all applicable columns will be exploded.
74+ * @return A new [DataFrame] with exploded columns.
75+ */
2276@Refine
2377@Interpretable(" Explode0" )
2478public fun <T > DataFrame<T>.explode (
2579 dropEmpty : Boolean = true,
26- selector : ColumnsSelector <T , * > = defaultExplodeColumns,
27- ): DataFrame <T > = explodeImpl(dropEmpty, selector)
28-
80+ columns : ColumnsSelector <T , * > = defaultExplodeColumns,
81+ ): DataFrame <T > = explodeImpl(dropEmpty, columns)
82+
83+ /* *
84+ * {@include [ExplodeDocs]}
85+ * {@include [SelectingColumns.ColumnNames]}
86+ *
87+ * #### Example
88+ *
89+ * ```kotlin
90+ * // Explodes the "tags" and "scores" columns, where
91+ * // "tags" is a `List<String>` and "scores" is a `List<Int>`
92+ * val exploded = df.explode("tags", "scores")
93+ * ```
94+ *
95+ * @param dropEmpty If `true`, removes rows with empty lists or DataFrames.
96+ * If `false`, such rows will be exploded into `null` values.
97+ * @param columns The [column names][String] used to select columns to explode.
98+ * If not specified, all applicable columns will be exploded.
99+ * @return A new [DataFrame] with exploded columns.
100+ */
29101public fun <T > DataFrame<T>.explode (vararg columns : String , dropEmpty : Boolean = true): DataFrame <T > =
30102 explode(dropEmpty) { columns.toColumnSet() }
31103
@@ -43,11 +115,73 @@ public fun <T, C> DataFrame<T>.explode(vararg columns: KProperty<C>, dropEmpty:
43115
44116// region explode DataRow
45117
118+ /* *
119+ * Splits list-like values in the specified [\columns] of this [DataRow] and spreads them vertically —
120+ * that is, it adds a separate row for each element (one value per row)
121+ * and combine them into new [DataFrame].
122+ * Values in all other columns are duplicated to preserve row context.
123+ *
124+ * If no [\columns] are specified, all columns (at any depth) containing
125+ * [List] or [DataFrame] values will be exploded.
126+ *
127+ * If [dropEmpty] is `true`, the result will exclude rows with empty lists or DataFrames.
128+ * If `false`, such values will be exploded into `null`.
129+ *
130+ * Returns a new [DataFrame] expanded into multiple rows based on the exploded columns.
131+ *
132+ * Each exploded column will have a new type (`List<T>` → `T`).
133+ * When several columns are exploded in one operation, lists in different columns will be aligned.
134+ *
135+ * @include [SelectingColumns.ColumnGroupsAndNestedColumnsMention]
136+ *
137+ * For more information, see: {@include [DocumentationUrls.Explode]}
138+ *
139+ * ### This `explode` overload
140+ */
141+ @ExcludeFromSources
142+ internal interface ExplodeDataRowDocs
143+
144+ /* *
145+ * {@include [ExplodeDataRowDocs]}
146+ * {@include [SelectingColumns.Dsl]}
147+ *
148+ * #### Example
149+ *
150+ * ```kotlin
151+ * // Explodes the `hobbies` and `scores` values of the row,
152+ * // of types `List<String>` and `List<Int>`, respectively
153+ * row.explode { hobbies and scores }
154+ * ```
155+ *
156+ * @param dropEmpty If `true`, removes rows with empty lists or DataFrames.
157+ * If `false`, such rows will be exploded into `null` values.
158+ * @param columns The [ColumnsSelector] used to select columns to explode.
159+ * If not specified, all applicable columns will be exploded.
160+ * @return A new [DataFrame] with exploded columns from this [DataRow].
161+ */
46162public fun <T > DataRow<T>.explode (
47163 dropEmpty : Boolean = true,
48- selector : ColumnsSelector <T , * > = defaultExplodeColumns,
49- ): DataFrame <T > = toDataFrame().explode(dropEmpty, selector)
50-
164+ columns : ColumnsSelector <T , * > = defaultExplodeColumns,
165+ ): DataFrame <T > = toDataFrame().explode(dropEmpty, columns)
166+
167+ /* *
168+ * {@include [ExplodeDataRowDocs]}
169+ * {@include [SelectingColumns.ColumnNames]}
170+ *
171+ * #### Example
172+ *
173+ * ```kotlin
174+ * // Explodes the `hobbies` and `scores` values of the row,
175+ * // of types `List<String>` and `List<Int>`, respectively
176+ * row.explode("hobbies", "scores")
177+ * ```
178+ *
179+ * @param dropEmpty If `true`, removes rows with empty lists or DataFrames.
180+ * If `false`, such rows will be exploded into `null` values.
181+ * @param columns The [column names][String] used to select columns to explode.
182+ * If not specified, all applicable columns will be exploded.
183+ * @return A new [DataFrame] with exploded columns from this [DataRow].
184+ */
51185public fun <T > DataRow<T>.explode (vararg columns : String , dropEmpty : Boolean = true): DataFrame <T > =
52186 explode(dropEmpty) { columns.toColumnSet() }
53187
@@ -65,9 +199,31 @@ public fun <T, C> DataRow<T>.explode(vararg columns: KProperty<C>, dropEmpty: Bo
65199
66200// region explode DataColumn
67201
202+ /* *
203+ * Splits list-like values in this [DataColumn] and spreads them vertically —
204+ * that is, it adds a separate row for each element (one value per row).
205+ *
206+ * Returns a new [DataColumn] with the exploded values.
207+ * The resulting column will have a new type (`List<T>` → `T`).
208+ *
209+ * For more information, see: {@include [DocumentationUrls.Explode]}
210+ *
211+ * @return A new [DataColumn] with exploded values.
212+ */
68213@JvmName(" explodeList" )
69214public fun <T > DataColumn<Collection<T>>.explode (): DataColumn <T > = explodeImpl() as DataColumn <T >
70215
216+ /* *
217+ * Explodes a [DataColumn] of [DataFrame] values into a single [ColumnGroup].
218+ *
219+ * Each nested [DataFrame] is unwrapped, and its columns are placed side by side
220+ * within a column group named after the original column.
221+ * The number of resulting rows equals the total number of rows across all nested DataFrames.
222+ *
223+ * For more information, see: {@include [DocumentationUrls.Explode]}
224+ *
225+ * @return A [ColumnGroup] containing the concatenated contents of all nested DataFrames.
226+ */
71227@JvmName(" explodeFrames" )
72228public fun <T > DataColumn<DataFrame<T>>.explode (): ColumnGroup <T > = concat().asColumnGroup(name())
73229
0 commit comments