-
Notifications
You must be signed in to change notification settings - Fork 75
Cum sum fixes #1467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cum sum fixes #1467
Changes from all commits
2948991
64de747
8c5af58
c8af8d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,15 +24,19 @@ import kotlin.reflect.KProperty | |
* from the first cell to the last cell. | ||
* | ||
* __NOTE:__ If the column contains nullable values and [skipNA\] is set to `true`, | ||
* null and NaN values are skipped when computing the cumulative sum. | ||
* When false, all values after the first NA will be NaN (for Double and Float columns) | ||
* or null (for integer columns). | ||
* `null` and `NaN` values are skipped when computing the cumulative sum. | ||
* When `false`, all values after the first `NA` will be `NaN` (for [Double] and [Float] columns) | ||
* or `null` (for other columns). | ||
* | ||
* {@get [CumSumDocs.CUMSUM_PARAM] @param [columns\] | ||
* The names of the columns to apply cumSum operation.} | ||
* `cumSum` only works on columns that contain solely primitive numbers. | ||
* | ||
* @param [skipNA\] Whether to skip null and NaN values (default: `true`). | ||
* Similar to [sum][sum], [Byte][Byte]- and [Short][Short]-columns are converted to [Int][Int]. | ||
* | ||
* {@get [CumSumDocs.CUMSUM_PARAM] @param [columns\] The selection of the columns to apply the `cumSum` operation to. | ||
* If not provided, `cumSum` will be applied to all primitive columns [at any depth][ColumnsSelectionDsl.colsAtAnyDepth]. | ||
* } | ||
* | ||
* @param [skipNA\] Whether to skip `null` and `NaN` values (default: `true`). | ||
* @return A new {@get [CumSumDocs.DATA_TYPE]} of the same type with the cumulative sums. | ||
* | ||
* {@get [CumSumDocs.CUMSUM_PARAM] @see [Selecting Columns][SelectSelectingOptions].} | ||
|
@@ -41,8 +45,11 @@ import kotlin.reflect.KProperty | |
@ExcludeFromSources | ||
@Suppress("ClassName") | ||
private interface CumSumDocs { | ||
|
||
// Can be emptied to disable information about selecting columns | ||
interface CUMSUM_PARAM | ||
|
||
// Either [DataColumn] or [DataFrame] | ||
interface DATA_TYPE | ||
} | ||
|
||
|
@@ -157,10 +164,11 @@ public fun <T> DataFrame<T>.cumSum( | |
* {@set [CumSumDocs.DATA_TYPE] [DataFrame]} | ||
* {@set [CumSumDocs.CUMSUM_PARAM]} | ||
*/ | ||
@Refine | ||
@Interpretable("DataFrameCumSum0") | ||
public fun <T> DataFrame<T>.cumSum(skipNA: Boolean = defaultCumSumSkipNA): DataFrame<T> = | ||
cumSum(skipNA) { | ||
// TODO keep at any depth? | ||
colsAtAnyDepth().filter { it.isNumber() }.cast() | ||
colsAtAnyDepth().filter { it.isPrimitiveOrMixedNumber() }.cast() | ||
} | ||
|
||
// endregion | ||
|
@@ -212,10 +220,11 @@ public fun <T, G> GroupBy<T, G>.cumSum( | |
* {@set [CumSumDocs.DATA_TYPE] [GroupBy]} | ||
* {@set [CumSumDocs.CUMSUM_PARAM]} | ||
*/ | ||
@Refine | ||
@Interpretable("GroupByCumSum0") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are marking the functions for Compiler Plugin, should we add a test for this trivial case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. testing what? and how? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, usually i simply annotate functions and later adjust if anything is wrong (one time i forgot Refine annotation) |
||
public fun <T, G> GroupBy<T, G>.cumSum(skipNA: Boolean = defaultCumSumSkipNA): GroupBy<T, G> = | ||
cumSum(skipNA) { | ||
// TODO keep at any depth? | ||
colsAtAnyDepth().filter { it.isNumber() }.cast() | ||
colsAtAnyDepth().filter { it.isPrimitiveOrMixedNumber() }.cast() | ||
} | ||
|
||
// endregion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sum-sum! Bye-Bye-Bye!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, unfortunately, there are KDoc rendering issues if you don't alias the types here