-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fix(rust, python) Summation on empty series evaluates to Some(0)
#5773
Conversation
2c235f8
to
4ee4c69
Compare
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.
Thanks @andrewpollack. I have left a few remarks.
polars/polars-core/src/series/mod.rs
Outdated
@@ -1038,6 +1047,23 @@ mod test { | |||
let _ = series.slice(4, 2); | |||
} | |||
|
|||
#[test] | |||
fn empty_series_sum_evals_zero() { |
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.
Could these tests moved to the python tests? We want to reduce the testing ci time. Rust tests need a long time to compile/run.
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.
Sure! Looking to move now, and resolving why the Python test for an empty sum is still returning None
31d701e
to
1b1963c
Compare
From https://github.com/pola-rs/polars/blob/master/py-polars/src/series.rs#L482 , it looks like I'll need to adjust |
1b1963c
to
5d9302e
Compare
/// | ||
/// If the [`DataType`] is one of `{Int8, UInt8, Int16, UInt16}` the `Series` is | ||
/// first cast to `Int64` to prevent overflow issues. | ||
pub fn sum_as_series(&self) -> Series { | ||
use DataType::*; | ||
if self.is_empty() && self.dtype().is_numeric() { | ||
return Series::new("", [0]) |
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.
Almost there. Int8 | UInt8 | Int16 | UInt16
should be Int64
.
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.
Since we recursively call into sum_as_series
, won't they be converted to Int64 on the second call? Or should I implement this logic to save on an unnecessary call?
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.
Oh, right. Missed that one.
Nope. This is good!
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.
Awesome! Thank you for your feedbacks on this PR 😸
Some(0)
Some(0)
Thanks @andrewpollack 🙇 Merging in. 👍 |
Some(0)
Some(0)
Closes: #5604
Changes:
Series::sum()
on an empty series now evaluates toSome(0)
.Series::sum_as_series()
on an empty series now returns a Series with a single zero'd value. This is done to enable the above change in both Rust and Python libraries.test_arithmetic_empty
,test_arithmetic_null
.I chose to add logic directly to
sum_as_series()
as to reduce the blast radius of this new logic. Please let me know if any changes are needed, including location of tests!