Skip to content

Commit 937c9d7

Browse files
authored
Guard calling is_nan on scalar value on dtype being a float (#8593)
Downcasting scalars is more expensive than checking dtypes
1 parent b4c85b6 commit 937c9d7

4 files changed

Lines changed: 9 additions & 4 deletions

File tree

vortex-array/src/aggregate_fn/fns/max/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl MaxPartial {
6767
}
6868

6969
fn is_poisoned(&self) -> bool {
70-
self.max.as_ref().is_some_and(scalar_is_nan)
70+
self.element_dtype.is_float() && self.max.as_ref().is_some_and(scalar_is_nan)
7171
}
7272
}
7373

vortex-array/src/aggregate_fn/fns/min/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl MinPartial {
6767
}
6868

6969
fn is_poisoned(&self) -> bool {
70-
self.min.as_ref().is_some_and(scalar_is_nan)
70+
self.element_dtype.is_float() && self.min.as_ref().is_some_and(scalar_is_nan)
7171
}
7272
}
7373

vortex-array/src/aggregate_fn/fns/min_max/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ pub(crate) fn nan_scalar(dtype: &DType) -> Scalar {
149149

150150
/// Whether a scalar holds a primitive float NaN value.
151151
pub(crate) fn scalar_is_nan(scalar: &Scalar) -> bool {
152+
if !scalar.dtype().is_float() {
153+
return false;
154+
}
155+
152156
scalar.as_primitive_opt().is_some_and(|p| p.is_nan())
153157
}
154158

@@ -233,7 +237,7 @@ impl MinMaxPartial {
233237

234238
/// Whether the partial state is poisoned to NaN.
235239
fn is_poisoned(&self) -> bool {
236-
self.min.as_ref().is_some_and(scalar_is_nan)
240+
self.element_dtype.is_float() && self.min.as_ref().is_some_and(scalar_is_nan)
237241
}
238242
}
239243

vortex-array/src/dtype/ptype.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use num_traits::Unsigned;
2121
use num_traits::bounds::UpperBounded;
2222
use vortex_error::VortexError;
2323
use vortex_error::VortexResult;
24+
use vortex_error::vortex_bail;
2425
use vortex_error::vortex_err;
2526

2627
use crate::dtype::DType;
@@ -845,7 +846,7 @@ impl TryFrom<&DType> for PType {
845846
if let DType::Primitive(p, _) = value {
846847
Ok(*p)
847848
} else {
848-
Err(vortex_err!("Cannot convert DType {} into PType", value))
849+
vortex_bail!("Cannot convert DType {value} into PType")
849850
}
850851
}
851852
}

0 commit comments

Comments
 (0)