File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
polars-arrow/src/kernels/rolling
polars-core/src/chunked_array/ops Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ type WindowSize = usize;
2222type Len = usize ;
2323
2424#[ inline]
25+ /// NaN will be smaller than every valid value
2526pub fn compare_fn_nan_min < T > ( a : & T , b : & T ) -> Ordering
2627where
2728 T : PartialOrd + IsFloat ,
4243}
4344
4445#[ inline]
46+ /// NaN will be larger than every valid value
4547pub fn compare_fn_nan_max < T > ( a : & T , b : & T ) -> Ordering
4648where
4749 T : PartialOrd + IsFloat ,
Original file line number Diff line number Diff line change 11//! Implementations of the ChunkAgg trait.
2+ use std:: cmp:: Ordering ;
23use std:: ops:: Add ;
34
45use arrow:: compute;
56use arrow:: types:: simd:: Simd ;
67use num:: { Float , ToPrimitive } ;
8+ use polars_arrow:: kernels:: rolling:: { compare_fn_nan_max, compare_fn_nan_min} ;
79use polars_arrow:: prelude:: QuantileInterpolOptions ;
810
911use crate :: chunked_array:: ChunkedArray ;
8890 IsSorted :: Not => self
8991 . downcast_iter ( )
9092 . filter_map ( compute:: aggregate:: min_primitive)
91- . fold_first_ ( |acc, v| if acc < v { acc } else { v } ) ,
93+ . fold_first_ ( |acc, v| {
94+ if matches ! ( compare_fn_nan_max( & acc, & v) , Ordering :: Less ) {
95+ acc
96+ } else {
97+ v
98+ }
99+ } ) ,
92100 }
93101 }
94102
@@ -111,7 +119,13 @@ where
111119 IsSorted :: Not => self
112120 . downcast_iter ( )
113121 . filter_map ( compute:: aggregate:: max_primitive)
114- . fold_first_ ( |acc, v| if acc > v { acc } else { v } ) ,
122+ . fold_first_ ( |acc, v| {
123+ if matches ! ( compare_fn_nan_min( & acc, & v) , Ordering :: Greater ) {
124+ acc
125+ } else {
126+ v
127+ }
128+ } ) ,
115129 }
116130 }
117131
You can’t perform that action at this time.
0 commit comments