Skip to content

Commit c790d42

Browse files
committed
Fixes to the documentation for the last and lastOrNull functions after review
1 parent f3f4e6c commit c790d42

File tree

1 file changed

+99
-66
lines changed
  • core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api

1 file changed

+99
-66
lines changed

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

Lines changed: 99 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ import kotlin.reflect.KProperty
3333
/**
3434
* Returns the last value in this [DataColumn].
3535
*
36-
* See also [lastOrNull], [first], [take], [takeLast].
36+
* @see [lastOrNull]
37+
* @see [first]
38+
* @see [take]
39+
* @see [takeLast]
3740
*
3841
* @return The last value in this [DataColumn].
3942
*
@@ -44,7 +47,10 @@ public fun <T> DataColumn<T>.last(): T = get(size - 1)
4447
/**
4548
* Returns the last value in this [DataColumn]. If the [DataColumn] is empty, returns `null`.
4649
*
47-
* See also [last], [first], [take], [takeLast].
50+
* @see [last]
51+
* @see [first]
52+
* @see [take]
53+
* @see [takeLast]
4854
*
4955
* @return The last value in this [DataColumn], or `null` if the [DataColumn] is empty.
5056
*/
@@ -60,9 +66,12 @@ public fun <T> DataColumn<T>.lastOrNull(): T? = if (size > 0) last() else null
6066
* df.amount.last { it > 100 }
6167
* ```
6268
*
63-
* See also [lastOrNull], [first], [take], [takeLast].
69+
* @see [lastOrNull]
70+
* @see [first]
71+
* @see [take]
72+
* @see [takeLast]
6473
*
65-
* @param predicate A lambda expression used to get the last value
74+
* @param [predicate] A lambda expression used to get the last value
6675
* that satisfies a condition specified in this expression.
6776
* This predicate takes a value from the [DataColumn] as an input
6877
* and returns `true` if the value satisfies the condition or `false` otherwise.
@@ -82,20 +91,23 @@ public inline fun <T> DataColumn<T>.last(predicate: (T) -> Boolean): T = values.
8291
* ### Example
8392
* ```kotlin
8493
* // In a DataFrame of financial transactions sorted by time,
85-
* // obtain the amount of the most recent financial transaction over 100 euros,
94+
* // find the amount of the most recent financial transaction over 100 euros,
8695
* // or 'null' if there is no such transaction
8796
* df.amount.lastOrNull { it > 100 }
8897
* ```
8998
*
90-
* See also [last], [first], [take], [takeLast].
99+
* @see [last]
100+
* @see [first]
101+
* @see [take]
102+
* @see [takeLast]
91103
*
92-
* @param predicate A lambda expression used to get the last value
104+
* @param [predicate] A lambda expression used to get the last value
93105
* that satisfies a condition specified in this expression.
94106
* This predicate takes a value from the [DataColumn] as an input
95107
* and returns `true` if the value satisfies the condition or `false` otherwise.
96108
*
97109
* @return The last value in this [DataColumn] that matches the given [predicate],
98-
* or `null` if the [DataColumn] contains no element matching the [predicate].
110+
* or `null` if the [DataColumn] contains no elements matching the [predicate].
99111
*/
100112
public inline fun <T> DataColumn<T>.lastOrNull(predicate: (T) -> Boolean): T? = values.lastOrNull(predicate)
101113

@@ -120,9 +132,13 @@ public inline fun <T> DataColumn<T>.lastOrNull(predicate: (T) -> Boolean): T? =
120132
* df.lastOrNull { amount > 100 }
121133
* ```
122134
*
123-
* See also [last], [first], [take], [takeLast], [takeWhile].
135+
* @see [DataFrame.last]
136+
* @see [DataFrame.first]
137+
* @see [DataFrame.take]
138+
* @see [DataFrame.takeLast]
139+
* @see [takeWhile]
124140
*
125-
* @param predicate A [row filter][RowFilter] used to get the last value
141+
* @param [predicate] A [row filter][RowFilter] used to get the last value
126142
* that satisfies a condition specified in this filter.
127143
*
128144
* @return A [DataRow] containing the last row that matches the given [predicate],
@@ -145,9 +161,13 @@ public inline fun <T> DataFrame<T>.lastOrNull(predicate: RowFilter<T>): DataRow<
145161
* df.last { amount > 100 }
146162
* ```
147163
*
148-
* See also [lastOrNull], [first], [take], [takeLast], [takeWhile].
164+
* @see [DataFrame.lastOrNull]
165+
* @see [DataFrame.first]
166+
* @see [DataFrame.take]
167+
* @see [DataFrame.takeLast]
168+
* @see [DataFrame.takeWhile]
149169
*
150-
* @param predicate A [row filter][RowFilter] used to get the last value
170+
* @param [predicate] A [row filter][RowFilter] used to get the last value
151171
* that satisfies a condition specified in this filter.
152172
*
153173
* @return A [DataRow] containing the last row that matches the given [predicate].
@@ -162,7 +182,10 @@ public inline fun <T> DataFrame<T>.last(predicate: RowFilter<T>): DataRow<T> =
162182
/**
163183
* Returns the last [row][DataRow] in this [DataFrame]. If the [DataFrame] does not contain any rows, returns `null`.
164184
*
165-
* See also [last], [first], [take], [takeLast].
185+
* @see [DataFrame.last]
186+
* @see [DataFrame.first]
187+
* @see [DataFrame.take]
188+
* @see [DataFrame.takeLast]
166189
*
167190
* @return A [DataRow] containing the last row in this [DataFrame], or `null` if the [DataFrame] is empty.
168191
*/
@@ -171,7 +194,10 @@ public fun <T> DataFrame<T>.lastOrNull(): DataRow<T>? = if (nrow > 0) get(nrow -
171194
/**
172195
* Returns the last [row][DataRow] in this [DataFrame].
173196
*
174-
* See also [lastOrNull], [first], [take], [takeLast].
197+
* @see [DataFrame.lastOrNull]
198+
* @see [DataFrame.first]
199+
* @see [DataFrame.take]
200+
* @see [DataFrame.takeLast]
175201
*
176202
* @return A [DataRow] containing the last row in this [DataFrame].
177203
*
@@ -189,15 +215,14 @@ public fun <T> DataFrame<T>.last(): DataRow<T> {
189215
// region GroupBy
190216

191217
/**
192-
* Gets the last [row][DataRow] from each group of the given [GroupBy]
218+
* [Reduces][GroupByDocs.Reducing] the groups of this [GroupBy]
219+
* by taking the last [row][DataRow] from each group,
193220
* and returns a [ReducedGroupBy] containing these rows
194-
* (one row per group, each row is the last row in its group).
221+
* (one [row][DataRow] per group, each [row][DataRow] is the last [row][DataRow] in its group).
195222
*
196-
* If the group in [GroupBy] is empty,
197-
* the corresponding row in [ReducedGroupBy] will contain `null` values for all columns in the group,
198-
* except the column with the grouping key.
199-
*
200-
* See also [first].
223+
* If a group in this [GroupBy] is empty,
224+
* the corresponding [row][DataRow] in the resulting [ReducedGroupBy] will contain `null` values
225+
* for all columns in the group, except the grouping key.
201226
*
202227
* ### Example
203228
* ```kotlin
@@ -206,16 +231,19 @@ public fun <T> DataFrame<T>.last(): DataRow<T> {
206231
* df.groupBy { orderId }.last()
207232
* ```
208233
*
234+
* @see [GroupBy.first]
235+
*
209236
* @return A [ReducedGroupBy] containing the last [row][DataRow]
210-
* (or a row with `null` values, except the grouping key) from each group.
237+
* (or a [row][DataRow] with `null` values, except the grouping key) from each group.
211238
*/
212239
@Interpretable("GroupByReducePredicate")
213240
public fun <T, G> GroupBy<T, G>.last(): ReducedGroupBy<T, G> = reduce { lastOrNull() }
214241

215242
/**
216-
* Gets from each group of the given [GroupBy] the last [row][DataRow] satisfying the given [predicate],
217-
* and returns a [ReducedGroupBy] containing these rows (one row per group,
218-
* each row is the last row in its group that satisfies the [predicate]).
243+
* [Reduces][GroupByDocs.Reducing] the groups of this [GroupBy]
244+
* by taking from each group the last [row][DataRow] satisfying the given [predicate],
245+
* and returns a [ReducedGroupBy] containing these rows (one [row][DataRow] per group,
246+
* each [row][DataRow] is the last [row][DataRow] in its group that satisfies the [predicate]).
219247
*
220248
* If the group in [GroupBy] contains no matching rows,
221249
* the corresponding row in [ReducedGroupBy] will contain `null` values for all columns in the group,
@@ -225,20 +253,20 @@ public fun <T, G> GroupBy<T, G>.last(): ReducedGroupBy<T, G> = reduce { lastOrNu
225253
*
226254
* @include [SelectingColumns.ColumnGroupsAndNestedColumnsMention]
227255
*
228-
* See also [first].
229-
*
230256
* ### Example
231257
* ```kotlin
232258
* // In a DataFrame of order status logs sorted by time,
233259
* // find the most recent status shown to the customer for each order
234260
* df.groupBy { orderId }.last { !isInternal }
235261
* ```
236262
*
237-
* @param predicate A [row filter][RowFilter] used to get the last value
263+
* @see [GroupBy.first]
264+
*
265+
* @param [predicate] A [row filter][RowFilter] used to get the last value
238266
* that satisfies a condition specified in this filter.
239267
*
240268
* @return A [ReducedGroupBy] containing the last [row][DataRow] matching the [predicate]
241-
* (or a row with `null` values, except the grouping key) from each group.
269+
* (or a [row][DataRow] with `null` values, except the grouping key) from each group.
242270
*/
243271
@Interpretable("GroupByReducePredicate")
244272
public fun <T, G> GroupBy<T, G>.last(predicate: RowFilter<G>): ReducedGroupBy<T, G> = reduce { lastOrNull(predicate) }
@@ -248,13 +276,12 @@ public fun <T, G> GroupBy<T, G>.last(predicate: RowFilter<G>): ReducedGroupBy<T,
248276
// region Pivot
249277

250278
/**
251-
* Reduces this [Pivot] by taking the last [row][DataRow] from each group, and returns a [ReducedPivot]
252-
* that contains the last row from the corresponding group in each column.
279+
* [Reduces][PivotDocs.Reducing] this [Pivot] by taking the last [row][DataRow] from each group,
280+
* and returns a [ReducedPivot] that contains the last [row][DataRow] from the corresponding group in each column.
253281
*
254-
* See also:
255-
* - [pivot];
256-
* - common [reduce][Pivot.reduce];
257-
* - [first].
282+
* @see [pivot]
283+
* @see [Pivot.reduce]
284+
* @see [Pivot.first]
258285
*
259286
* For more information about [Pivot] with examples: {@include [DocumentationUrls.Pivot]}
260287
*
@@ -270,14 +297,13 @@ public fun <T, G> GroupBy<T, G>.last(predicate: RowFilter<G>): ReducedGroupBy<T,
270297
public fun <T> Pivot<T>.last(): ReducedPivot<T> = reduce { lastOrNull() }
271298

272299
/**
273-
* Reduces this [Pivot] by taking from each group the last [row][DataRow] satisfying the given [predicate],
274-
* and returns a [ReducedPivot] that contains the last row, matching the [predicate],
275-
* from the corresponding group in each column.
300+
* [Reduces][PivotDocs.Reducing] this [Pivot] by taking from each group the last [row][DataRow]
301+
* satisfying the given [predicate], and returns a [ReducedPivot] that contains the last [row][DataRow],
302+
* matching the [predicate], from the corresponding group in each column.
276303
*
277-
* See also:
278-
* - [pivot];
279-
* - common [reduce][Pivot.reduce];
280-
* - [first].
304+
* @see [pivot]
305+
* @see [Pivot.reduce]
306+
* @see [Pivot.first]
281307
*
282308
* For more information about [Pivot] with examples: {@include [DocumentationUrls.Pivot]}
283309
*
@@ -293,11 +319,11 @@ public fun <T> Pivot<T>.last(): ReducedPivot<T> = reduce { lastOrNull() }
293319
* df.pivot { type }.last { price < 500_000 }
294320
* ```
295321
*
296-
* @param predicate A [row filter][RowFilter] used to get the last value
322+
* @param [predicate] A [row filter][RowFilter] used to get the last value
297323
* that satisfies a condition specified in this filter.
298324
*
299-
* @return A [ReducedPivot] containing in each column the last [row][DataRow] that satisfies the [predicate],
300-
* from the corresponding group (or a row with `null` values)
325+
* @return A [ReducedPivot] containing in each column the last [row][DataRow]
326+
* that satisfies the [predicate], from the corresponding group (or a [row][DataRow] with `null` values)
301327
*/
302328
public fun <T> Pivot<T>.last(predicate: RowFilter<T>): ReducedPivot<T> = reduce { lastOrNull(predicate) }
303329

@@ -306,17 +332,19 @@ public fun <T> Pivot<T>.last(predicate: RowFilter<T>): ReducedPivot<T> = reduce
306332
// region PivotGroupBy
307333

308334
/**
309-
* Reduces this [PivotGroupBy] by taking the last [row][DataRow] from each combined [pivot] + [groupBy] group,
310-
* and returns a [ReducedPivotGroupBy] that contains the last row from each corresponding group.
335+
* [Reduces][PivotGroupByDocs.Reducing] this [PivotGroupBy] by taking the last [row][DataRow]
336+
* from each combined [pivot] + [groupBy] group, and returns a [ReducedPivotGroupBy]
337+
* that contains the last row from each corresponding group.
311338
* If any combined [pivot] + [groupBy] group in [PivotGroupBy] is empty, in the resulting [ReducedPivotGroupBy]
312-
* it will be represented by a row with `null` values (except the grouping key).
339+
* it will be represented by a [row][DataRow] with `null` values (except the grouping key).
313340
*
314-
* See also:
315-
* - [pivot], [Pivot.groupBy] and [GroupBy.pivot];
316-
* - common [reduce][PivotGroupBy.reduce];
317-
* - [first].
341+
* @see [pivot]
342+
* @see [Pivot.groupBy]
343+
* @see [GroupBy.pivot]
344+
* @see [PivotGroupBy.reduce]
345+
* @see [PivotGroupBy.first]
318346
*
319-
* For more information about [Pivot] with examples: {@include [DocumentationUrls.Pivot]}
347+
* For more information about [PivotGroupBy] with examples: {@include [DocumentationUrls.PivotGroupBy]}
320348
*
321349
* ### Example
322350
* ```kotlin
@@ -327,27 +355,32 @@ public fun <T> Pivot<T>.last(predicate: RowFilter<T>): ReducedPivot<T> = reduce
327355
* ```
328356
*
329357
* @return A [ReducedPivotGroupBy] containing in each combination of a [groupBy] key and a [pivot] key either
330-
* the last [row][DataRow] of the corresponding DataFrame formed by this pivot–group pair,
331-
* or a row with `null` values (except the grouping key) if this DataFrame is empty.
358+
* the last [row][DataRow] of the corresponding [DataFrame] formed by this pivot–group pair,
359+
* or a [row][DataRow] with `null` values (except the grouping key) if this [DataFrame] is empty.
332360
*/
333361
public fun <T> PivotGroupBy<T>.last(): ReducedPivotGroupBy<T> = reduce { lastOrNull() }
334362

335363
/**
336-
* Reduces this [PivotGroupBy] by taking from each combined [pivot] + [groupBy] group
337-
* the last [row][DataRow] satisfying the given [predicate]. Returns a [ReducedPivotGroupBy] that contains the last row
338-
* matching the [predicate] from each corresponding group.
364+
* [Reduces][PivotGroupByDocs.Reducing] this [PivotGroupBy]
365+
* by taking from each combined [pivot] + [groupBy] group the last [row][DataRow] satisfying the given [predicate].
366+
* Returns a [ReducedPivotGroupBy] that contains the last [row][DataRow], matching the [predicate],
367+
* from each corresponding group.
339368
* If any combined [pivot] + [groupBy] group in [PivotGroupBy] does not contain any rows matching the [predicate],
340-
* in the resulting [ReducedPivotGroupBy] it will be represented by a row with `null` values (except the grouping key).
369+
* in the resulting [ReducedPivotGroupBy] it will be represented by a [row][DataRow] with `null` values
370+
* (except the grouping key).
341371
*
342-
* See also:
343-
* - [pivot], [Pivot.groupBy] and [GroupBy.pivot];
344-
* - common [reduce][PivotGroupBy.reduce];
345-
* - [first].
372+
* @see [pivot]
373+
* @see [Pivot.groupBy]
374+
* @see [GroupBy.pivot]
375+
* @see [PivotGroupBy.reduce]
376+
* @see [PivotGroupBy.first]
346377
*
347378
* {@include [DocumentationUrls.PivotGroupBy]}
348379
*
349380
* {@include [DocumentationUrls.Pivot]}
350381
*
382+
* {@include [DocumentationUrls.GroupBy]}
383+
*
351384
* {@include [RowFilterDescription]}
352385
*
353386
* @include [SelectingColumns.ColumnGroupsAndNestedColumnsMention]
@@ -361,12 +394,12 @@ public fun <T> PivotGroupBy<T>.last(): ReducedPivotGroupBy<T> = reduce { lastOrN
361394
* df.pivot { type }.groupBy { city }.last { price < 500_000 }
362395
* ```
363396
*
364-
* @param predicate A [row filter][RowFilter] used to get the last value
397+
* @param [predicate] A [row filter][RowFilter] used to get the last value
365398
* that satisfies a condition specified in this filter.
366399
*
367400
* @return A [ReducedPivotGroupBy] containing in each combination of a [groupBy] key and a [pivot] key either
368-
* the last matching the [predicate] [row][DataRow] of the corresponding DataFrame formed by this pivot–group pair,
369-
* or a row with `null` values if this DataFrame does not contain any rows matching the [predicate].
401+
* the last matching the [predicate] [row][DataRow] of the corresponding [DataFrame] formed by this pivot–group pair,
402+
* or a [row][DataRow] with `null` values if this [DataFrame] does not contain any rows matching the [predicate].
370403
*/
371404
public fun <T> PivotGroupBy<T>.last(predicate: RowFilter<T>): ReducedPivotGroupBy<T> = reduce { lastOrNull(predicate) }
372405

0 commit comments

Comments
 (0)