-
Notifications
You must be signed in to change notification settings - Fork 73
Unified number types #1070
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
Unified number types #1070
Conversation
…ed solely by `sum` at the moment. I introduced a future-proof rewrite of the function and added support for unsigned- and big numbers. Moved it to a separate file and added tests. We will reuse this logic in more places later. NumbersAggregator now converts numbers in its input to a common number type before aggregating, not relying on smart-casts anymore. To avoid heavy reflection calls, types can be supplied to aggregateMixed() if you're aware of them.
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.
Looks nice! Need to test this new logic when get started with other statistical functions.
core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/types/UtilTests.kt
Outdated
Show resolved
Hide resolved
core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/statistics/sum.kt
Outdated
Show resolved
Hide resolved
core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/NumberTypeUtils.kt
Outdated
Show resolved
Hide resolved
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.
Really intersting innovation and extensible, thanks for graph theory puzzle here!
I'll rename common number types -> unified number type before merging, because I think that better reflects the idea. A "common type" of |
…d numbers", added central doc template with graph
Fixes #1068
Helps #961
Fixed
getCommonNumberType
andcommonNumberClass
functions that are used solely bysum
at the moment.I introduced a future-proof rewrite of the function and added support for unsigned- and big numbers. Moved it to a separate file and added tests. We will reuse this logic in more places later. I created a small DAG implementation for this, as it's smaller than yet another dependency.
The idea of this is that numbers can be converted lossless to a higher number type, so providing, say
UInt
andFloat
can be auto-converted toDouble
at runtime safely. The only place it's currently done is when collecting numbers across multiple columns and summing them, but I intend to reuse this logic in other statistical functions when needed, in parsing, or in JSON.NumbersAggregator
now converts numbers in its input to a common number type first, before aggregating, not relying on smart-casts anymore.To avoid heavy reflection calls, types can be supplied to aggregateMixed() if you're aware of them.