Skip to content

Commit f13bd01

Browse files
committed
Fixes to the distinct and distinctBy KDocs after review.
1 parent 91b2185 commit f13bd01

File tree

2 files changed

+57
-68
lines changed

2 files changed

+57
-68
lines changed

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

Lines changed: 55 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ import org.jetbrains.kotlinx.dataframe.DataRow
77
import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
88
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
99
import org.jetbrains.kotlinx.dataframe.annotations.Refine
10+
import org.jetbrains.kotlinx.dataframe.api.DistinctDocs.DESCRIPTION
11+
import org.jetbrains.kotlinx.dataframe.api.DistinctDocs.DISTINCT_PARAM
1012
import org.jetbrains.kotlinx.dataframe.api.DistinctDocs.DISTINCT_RETURN
13+
import org.jetbrains.kotlinx.dataframe.api.DistinctDocs.FUNCTION
14+
import org.jetbrains.kotlinx.dataframe.api.DistinctDocs.PHRASE_ENDING
1115
import org.jetbrains.kotlinx.dataframe.api.Select.SelectSelectingOptions
1216
import org.jetbrains.kotlinx.dataframe.columns.ColumnSet
13-
import org.jetbrains.kotlinx.dataframe.columns.SingleColumn
1417
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
1518
import org.jetbrains.kotlinx.dataframe.documentation.DocumentationUrls
1619
import org.jetbrains.kotlinx.dataframe.documentation.DslGrammarTemplateColumnsSelectionDsl.DslGrammarTemplate
1720
import org.jetbrains.kotlinx.dataframe.documentation.ExcludeFromSources
1821
import org.jetbrains.kotlinx.dataframe.documentation.Indent
22+
import org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns
1923
import org.jetbrains.kotlinx.dataframe.exceptions.DuplicateColumnNamesException
2024
import org.jetbrains.kotlinx.dataframe.impl.columns.DistinctColumnSet
2125
import org.jetbrains.kotlinx.dataframe.indices
@@ -25,54 +29,60 @@ import kotlin.reflect.KProperty
2529
// region DataFrame
2630

2731
/**
28-
* ## The {@get NAME Distinct} Operation
32+
* {@get [DESCRIPTION] Removes duplicated rows based on {@get [PHRASE_ENDING]}}.
2933
*
30-
* {@get DESCRIPTION It removes duplicated rows based on {@get PHRASE_ENDING}}.
31-
*
32-
* __NOTE:__ The [rows][DataRow] in the resulting [DataFrame] are in the same order
34+
* The [rows][DataRow] in the resulting [DataFrame] are in the same order
3335
* as they were in the original [DataFrame].
3436
*
35-
* {@get [DISTINCT_PARAM]}
37+
* See also {@get [FUNCTION] [distinctBy] that removes duplicated rows based on the specified columns
38+
* and keeps all the columns in the resulting [DataFrame].}
39+
*
40+
* @include [SelectingColumns.ColumnGroupsAndNestedColumnsMention]
41+
*
42+
* See [Selecting Columns][SelectSelectingOptions].
3643
*
37-
* {@get [DISTINCT_RETURN] @return A new [DataFrame] containing only distinct rows.}
44+
* For more information:
45+
*
46+
* {@include [DocumentationUrls.Distinct]}
47+
*
48+
* {@include [DocumentationUrls.DistinctBy]}
49+
*
50+
* {@get [DISTINCT_PARAM]}
3851
*
39-
* @see [Selecting Columns][SelectSelectingOptions].
40-
* @see {@include [DocumentationUrls.Distinct]}
41-
* @see {@include [DocumentationUrls.DistinctBy]}
52+
* @return {@get [DISTINCT_RETURN] A new [DataFrame] containing only distinct rows.}
4253
*/
4354
@ExcludeFromSources
4455
@Suppress("ClassName")
4556
private interface DistinctDocs {
4657
interface DISTINCT_PARAM
4758

4859
interface DISTINCT_RETURN
60+
61+
interface DESCRIPTION
62+
63+
interface PHRASE_ENDING
64+
65+
interface FUNCTION
4966
}
5067

5168
/**
5269
* {@include [DistinctDocs]}
53-
* {@set PHRASE_ENDING all columns}.
54-
* {@set [DistinctDocs.DISTINCT_PARAM]}
70+
* {@set [PHRASE_ENDING] all columns}
71+
* {@set [DISTINCT_PARAM]}
5572
*/
5673
public fun <T> DataFrame<T>.distinct(): DataFrame<T> = distinctBy { all() }
5774

5875
/**
5976
* {@include [DistinctDocs]}
60-
* {@set DESCRIPTION It selects the specified columns and keeps only distinct rows based on these selected columns}
61-
* {@set [DistinctDocs.DISTINCT_PARAM] @param [columns] The names of the columns to select
62-
* and to consider for evaluating distinct rows.}
63-
* {@set [DISTINCT_RETURN] @return A new [DataFrame] containing only selected columns and distinct rows.}
77+
* {@set [DESCRIPTION] Selects the specified columns and keeps only distinct rows based on these selected columns}
78+
* {@set [DISTINCT_PARAM] @param [columns\] The [ColumnsSelector] used to select columns
79+
* that will be included in the resulting [DataFrame] and considered for evaluating distinct rows.}
80+
* {@set [DISTINCT_RETURN] A new [DataFrame] containing only selected columns and distinct rows.}
6481
*/
6582
@Refine
6683
@Interpretable("Distinct0")
6784
public fun <T, C> DataFrame<T>.distinct(columns: ColumnsSelector<T, C>): DataFrame<T> = select(columns).distinct()
6885

69-
/**
70-
* {@include [DistinctDocs]}
71-
* {@set DESCRIPTION It selects the specified columns and keeps only distinct rows based on these selected columns}
72-
* {@set [DistinctDocs.DISTINCT_PARAM] @param [columns] The names of the columns to select
73-
* and to consider for evaluating distinct rows.}
74-
* {@set [DISTINCT_RETURN] @return A new [DataFrame] containing only selected columns and distinct rows.}
75-
*/
7686
@Deprecated(DEPRECATED_ACCESS_API)
7787
@AccessApiOverload
7888
public fun <T> DataFrame<T>.distinct(vararg columns: KProperty<*>): DataFrame<T> =
@@ -83,64 +93,47 @@ public fun <T> DataFrame<T>.distinct(vararg columns: KProperty<*>): DataFrame<T>
8393

8494
/**
8595
* {@include [DistinctDocs]}
86-
* {@set DESCRIPTION It selects the specified columns and keeps only distinct rows based on these selected columns}
87-
* {@set [DistinctDocs.DISTINCT_PARAM] @param [columns] The names of the columns to select
96+
* {@set [DESCRIPTION] Selects the specified columns and keeps only distinct rows based on these selected columns}
97+
* {@set [DISTINCT_PARAM] @param [columns\] The names of the columns to select
8898
* and to consider for evaluating distinct rows.}
89-
* {@set [DISTINCT_RETURN] @return A new [DataFrame] containing only selected columns and distinct rows.}
99+
* {@set [DISTINCT_RETURN] A new [DataFrame] containing only selected columns and distinct rows.}
90100
*/
91101
public fun <T> DataFrame<T>.distinct(vararg columns: String): DataFrame<T> = distinct { columns.toColumnSet() }
92102

93-
/**
94-
* {@include [DistinctDocs]}
95-
* {@set DESCRIPTION It selects the specified columns and keeps only distinct rows based on these selected columns}
96-
* {@set [DistinctDocs.DISTINCT_PARAM] @param [columns] The names of the columns to select
97-
* and to consider for evaluating distinct rows.}
98-
* {@set [DISTINCT_RETURN] @return A new [DataFrame] containing only selected columns and distinct rows.}
99-
*/
100103
@Deprecated(DEPRECATED_ACCESS_API)
101104
@AccessApiOverload
102105
public fun <T> DataFrame<T>.distinct(vararg columns: AnyColumnReference): DataFrame<T> =
103106
distinct { columns.toColumnSet() }
104107

105-
/**
106-
* {@include [DistinctDocs]}
107-
* {@set NAME DistinctBy}
108-
* {@set PHRASE_ENDING the specified columns}.
109-
* {@set [DistinctDocs.DISTINCT_PARAM] @param [columns]
110-
* The names of the columns to consider for evaluating distinct rows.}
111-
*/
112108
@Deprecated(DEPRECATED_ACCESS_API)
113109
@AccessApiOverload
114110
public fun <T> DataFrame<T>.distinctBy(vararg columns: KProperty<*>): DataFrame<T> =
115111
distinctBy { columns.toColumnSet() }
116112

117113
/**
118114
* {@include [DistinctDocs]}
119-
* {@set NAME DistinctBy}
120-
* {@set PHRASE_ENDING the specified columns}.
121-
* {@set [DistinctDocs.DISTINCT_PARAM] @param [columns]
115+
* {@set [PHRASE_ENDING] the specified columns}
116+
* {@set [FUNCTION] [distinct] that selects the specified columns
117+
* (if the columns are not specified, selects all columns)
118+
* and keeps only distinct rows based on these selected columns.}
119+
* {@set [DISTINCT_PARAM] @param [columns\]
122120
* The names of the columns to consider for evaluating distinct rows.}
123121
*/
124122
public fun <T> DataFrame<T>.distinctBy(vararg columns: String): DataFrame<T> = distinctBy { columns.toColumnSet() }
125123

126-
/**
127-
* {@include [DistinctDocs]}
128-
* {@set NAME DistinctBy}
129-
* {@set PHRASE_ENDING the specified columns}.
130-
* {@set [DistinctDocs.DISTINCT_PARAM] @param [columns]
131-
* The names of the columns to consider for evaluating distinct rows.}
132-
*/
133124
@Deprecated(DEPRECATED_ACCESS_API)
134125
@AccessApiOverload
135126
public fun <T> DataFrame<T>.distinctBy(vararg columns: AnyColumnReference): DataFrame<T> =
136127
distinctBy { columns.toColumnSet() }
137128

138129
/**
139130
* {@include [DistinctDocs]}
140-
* {@set NAME DistinctBy}
141-
* {@set PHRASE_ENDING the specified columns}.
142-
* {@set [DistinctDocs.DISTINCT_PARAM] @param [columns]
143-
* The names of the columns to consider for evaluating distinct rows.}
131+
* {@set [PHRASE_ENDING] the specified columns}
132+
* {@set [FUNCTION] [distinct] that selects the specified columns
133+
* (if the columns are not specified, selects all columns)
134+
* and keeps only distinct rows based on these selected columns.}
135+
* {@set [DISTINCT_PARAM] @param [columns\] The [ColumnsSelector] used to select columns
136+
* that will be considered for evaluating distinct rows.}
144137
*/
145138
public fun <T, C> DataFrame<T>.distinctBy(columns: ColumnsSelector<T, C>): DataFrame<T> {
146139
val cols = get(columns)
@@ -153,15 +146,13 @@ public fun <T, C> DataFrame<T>.distinctBy(columns: ColumnsSelector<T, C>): DataF
153146
// region ColumnsSelectionDsl
154147

155148
/**
156-
* ##### Distinct {@include [ColumnsSelectionDslLink]}
149+
* Distinct {@include [ColumnsSelectionDslLink]}.
157150
*
158151
* See [Grammar] for all functions in this interface.
159152
*/
160153
public interface DistinctColumnsSelectionDsl {
161154

162155
/**
163-
* ## Distinct Grammar
164-
*
165156
* @include [DslGrammarTemplate]
166157
* {@set [DslGrammarTemplate.DEFINITIONS]
167158
* {@include [DslGrammarTemplate.ColumnSetDef]}
@@ -181,23 +172,21 @@ public interface DistinctColumnsSelectionDsl {
181172
}
182173

183174
/**
184-
* ## Distinct
185175
* Returns a new [ColumnSet] from [this] [ColumnSet] containing only distinct columns (by path).
186176
* This is useful when you've selected the same column multiple times but only want it once.
187177
*
188-
* NOTE: This doesn't solve [DuplicateColumnNamesException] if you've selected two columns with the same name.
178+
* This doesn't solve [DuplicateColumnNamesException] if you've selected two columns with the same name.
189179
* For this, you'll need to [rename][ColumnsSelectionDsl.named] one of the columns.
190180
*
191-
* ### Check out: [Grammar]
192-
*
193-
* #### For Example:
194-
* `df.`[select][DataFrame.select]` { (`[colsOf][SingleColumn.colsOf]`<`[Int][Int]`>() `[and][ColumnsSelectionDsl.and]` age).`[distinct][ColumnSet.distinct]`() }`
181+
* See also [Grammar], [named][ColumnsSelectionDsl.named], [simplify][ColumnsSelectionDsl.simplify].
195182
*
196-
* `df.`[select][DataFrame.select]` { `[colsAtAnyDepth][ColumnsSelectionDsl.colsAtAnyDepth]`().`[nameStartsWith][ColumnsSelectionDsl.nameStartsWith]`("order").`[distinct][ColumnSet.distinct]`() }`
183+
* ### Examples
184+
* ```kotlin
185+
* df.select { (colsOf<Int>() and age).distinct() }
186+
* df.select { colsAtAnyDepth().nameStartsWith("order").distinct() }
187+
* ```
197188
*
198189
* @return A new [ColumnSet] containing only distinct columns (by path).
199-
* @see ColumnsSelectionDsl.named
200-
* @see ColumnsSelectionDsl.simplify
201190
*/
202191
public fun <C> ColumnSet<C>.distinct(): ColumnSet<C> = DistinctColumnSet(this)
203192
}

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/DocumentationUrls.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ internal interface DocumentationUrls {
8484
/** [See `remove` on the documentation website.]({@include [Url]}/remove.html) */
8585
interface Remove
8686

87-
/** <a href="{@include [Url]}/distinct.html">See `distinct` on the documentation website.</a> */
87+
/** [See `distinct` on the documentation website.]({@include [Url]}/distinct.html) */
8888
interface Distinct
8989

90-
/** <a href="{@include [Url]}/distinct.html#distinctby">See `distinctBy` on the documentation website.</a> */
90+
/** [See `distinctBy` on the documentation website.]({@include [Url]}/distinct.html#distinctby) */
9191
interface DistinctBy
9292

9393
/** <a href="{@include [Url]}/flatten.html">See `flatten` on the documentation website.</a> */

0 commit comments

Comments
 (0)