Skip to content

Commit ea4d035

Browse files
committed
fixup! adding tests and comments, missing types for median, expanding cumSum
1 parent 860ea39 commit ea4d035

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ public fun <T : Number?> DataColumn<T>.cumSum(skipNA: Boolean = defaultCumSumSki
2929

3030
typeOf<Int>() -> cast<Int>().cumSum().cast()
3131

32-
// TODO cumSum for Byte returns Int but is cast back to T: Byte
33-
typeOf<Byte>() -> cast<Byte>().cumSum().cast()
32+
// TODO cumSum for Byte returns Int but is converted back to T: Byte, Issue #558
33+
typeOf<Byte>() -> cast<Byte>().cumSum().map { it.toByte() }.cast()
3434

35-
// TODO cumSum for Short returns Int but is cast back to T: Short
36-
typeOf<Short>() -> cast<Short>().cumSum().cast()
35+
// TODO cumSum for Short returns Int but is converted back to T: Short, Issue #558
36+
typeOf<Short>() -> cast<Short>().cumSum().map { it.toShort() }.cast()
3737

3838
typeOf<Int?>() -> cast<Int?>().cumSum(skipNA).cast()
3939

40-
// TODO cumSum for Byte? returns Int? but is cast back to T: Byte?
41-
typeOf<Byte?>() -> cast<Byte?>().cumSum(skipNA).cast()
40+
// TODO cumSum for Byte? returns Int? but is converted back to T: Byte?, Issue #558
41+
typeOf<Byte?>() -> cast<Byte?>().cumSum(skipNA).map { it?.toByte() }.cast()
4242

43-
// TODO cumSum for Short? returns Int? but is cast back to T: Short?
44-
typeOf<Short?>() -> cast<Short?>().cumSum(skipNA).cast()
43+
// TODO cumSum for Short? returns Int? but is converted back to T: Short?, Issue #558
44+
typeOf<Short?>() -> cast<Short?>().cumSum(skipNA).map { it?.toShort() }.cast()
4545

4646
typeOf<Long>() -> cast<Long>().cumSum().cast()
4747

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/math/sum.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ internal fun <T, R : Number> Iterable<T>.sumOf(type: KType, selector: (T) -> R?)
1313
return when (type.classifier) {
1414
Double::class -> sumOf(selector as ((T) -> Double)) as R
1515

16-
// careful, conversion to Double to Float occurs! TODO
16+
// careful, conversion to Double to Float occurs! TODO, Issue #558
1717
Float::class -> sumOf { (selector as ((T) -> Float))(it).toDouble() }.toFloat() as R
1818

1919
Int::class -> sumOf(selector as ((T) -> Int)) as R
2020

21-
// careful, cast to Int occurs! TODO
22-
Short::class -> sumOf { (selector as ((T) -> Short))(it).toInt() } as R
21+
// careful, conversion to Int occurs! TODO, Issue #558
22+
Short::class -> sumOf { (selector as ((T) -> Short))(it).toInt() }.toShort() as R
2323

24-
// careful, cast to Int occurs! TODO
25-
Byte::class -> sumOf { (selector as ((T) -> Byte))(it).toInt() } as R
24+
// careful, conversion to Int occurs! TODO, Issue #558
25+
Byte::class -> sumOf { (selector as ((T) -> Byte))(it).toInt() }.toByte() as R
2626

2727
Long::class -> sumOf(selector as ((T) -> Long)) as R
2828

0 commit comments

Comments
 (0)