Skip to content

Commit 64de747

Browse files
committed
updating cumSum default to use isPrimitiveOrMixedNumber
1 parent 2948991 commit 64de747

File tree

1 file changed

+15
-10
lines changed
  • core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api

1 file changed

+15
-10
lines changed

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,19 @@ import kotlin.reflect.KProperty
2424
* from the first cell to the last cell.
2525
*
2626
* __NOTE:__ If the column contains nullable values and [skipNA\] is set to `true`,
27-
* null and NaN values are skipped when computing the cumulative sum.
28-
* When false, all values after the first NA will be NaN (for Double and Float columns)
29-
* or null (for integer columns).
27+
* `null` and `NaN` values are skipped when computing the cumulative sum.
28+
* When `false`, all values after the first `NA` will be `NaN` (for [Double] and [Float] columns)
29+
* or `null` (for other columns).
3030
*
31-
* {@get [CumSumDocs.CUMSUM_PARAM] @param [columns\]
32-
* The names of the columns to apply cumSum operation.}
31+
* `cumSum` only works on columns that contain solely primitive numbers.
3332
*
34-
* @param [skipNA\] Whether to skip null and NaN values (default: `true`).
33+
* Similar to [sum][sum], [Byte][Byte]- and [Short][Short]-columns are converted to [Int][Int].
3534
*
35+
* {@get [CumSumDocs.CUMSUM_PARAM] @param [columns\] The selection of the columns to apply the `cumSum` operation to.
36+
* If not provided, `cumSum` will be applied to all primitive columns [at any depth][ColumnsSelectionDsl.colsAtAnyDepth].
37+
* }
38+
*
39+
* @param [skipNA\] Whether to skip `null` and `NaN` values (default: `true`).
3640
* @return A new {@get [CumSumDocs.DATA_TYPE]} of the same type with the cumulative sums.
3741
*
3842
* {@get [CumSumDocs.CUMSUM_PARAM] @see [Selecting Columns][SelectSelectingOptions].}
@@ -41,8 +45,11 @@ import kotlin.reflect.KProperty
4145
@ExcludeFromSources
4246
@Suppress("ClassName")
4347
private interface CumSumDocs {
48+
49+
// Can be emptied to disable information about selecting columns
4450
interface CUMSUM_PARAM
4551

52+
// Either [DataColumn] or [DataFrame]
4653
interface DATA_TYPE
4754
}
4855

@@ -159,8 +166,7 @@ public fun <T> DataFrame<T>.cumSum(
159166
*/
160167
public fun <T> DataFrame<T>.cumSum(skipNA: Boolean = defaultCumSumSkipNA): DataFrame<T> =
161168
cumSum(skipNA) {
162-
// TODO keep at any depth?
163-
colsAtAnyDepth().filter { it.isNumber() }.cast()
169+
colsAtAnyDepth().filter { it.isPrimitiveOrMixedNumber() }.cast()
164170
}
165171

166172
// endregion
@@ -214,8 +220,7 @@ public fun <T, G> GroupBy<T, G>.cumSum(
214220
*/
215221
public fun <T, G> GroupBy<T, G>.cumSum(skipNA: Boolean = defaultCumSumSkipNA): GroupBy<T, G> =
216222
cumSum(skipNA) {
217-
// TODO keep at any depth?
218-
colsAtAnyDepth().filter { it.isNumber() }.cast()
223+
colsAtAnyDepth().filter { it.isPrimitiveOrMixedNumber() }.cast()
219224
}
220225

221226
// endregion

0 commit comments

Comments
 (0)