Skip to content
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

refactor(rust): Fix nan-ignoring max/min in new-streaming #18593

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/polars-core/src/datatypes/any_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,14 @@ impl<'a> AnyValue<'a> {
)
}

pub fn is_nan(&self) -> bool {
match self {
AnyValue::Float32(f) => f.is_nan(),
AnyValue::Float64(f) => f.is_nan(),
_ => false,
}
}

pub fn is_null(&self) -> bool {
matches!(self, AnyValue::Null)
}
Expand Down
5 changes: 5 additions & 0 deletions crates/polars-core/src/scalar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ impl Scalar {
self.value.is_null()
}

#[inline(always)]
pub fn is_nan(&self) -> bool {
self.value.is_nan()
}

#[inline(always)]
pub fn value(&self) -> &AnyValue<'static> {
&self.value
Expand Down
8 changes: 6 additions & 2 deletions crates/polars-expr/src/reduce/min_max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ struct MinReduceState {

impl MinReduceState {
fn update_with_value(&mut self, other: &AnyValue<'static>) {
if self.value.is_null() || !other.is_null() && other < self.value.value() {
if self.value.is_null()
|| !other.is_null() && (other < self.value.value() || self.value.is_nan())
{
self.value.update(other.clone());
}
}
Expand Down Expand Up @@ -78,7 +80,9 @@ struct MaxReduceState {

impl MaxReduceState {
fn update_with_value(&mut self, other: &AnyValue<'static>) {
if self.value.is_null() || !other.is_null() && other > self.value.value() {
if self.value.is_null()
|| !other.is_null() && (other > self.value.value() || self.value.is_nan())
{
self.value.update(other.clone());
}
}
Expand Down
Loading