Skip to content

Commit

Permalink
return left
Browse files Browse the repository at this point in the history
  • Loading branch information
nameexhaustion committed Mar 14, 2024
1 parent 4fcd777 commit b0e5777
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
24 changes: 17 additions & 7 deletions crates/polars-core/src/chunked_array/ops/aggregate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use polars_utils::min_max::MinMax;
pub use quantile::*;
pub use var::*;

use self::search_sorted::{binary_search_array, SearchSortedSide};
use crate::chunked_array::ChunkedArray;
use crate::datatypes::{BooleanChunked, PolarsNumericType};
use crate::prelude::*;
Expand Down Expand Up @@ -99,17 +100,26 @@ where
match self.is_sorted_flag() {
IsSorted::Ascending => {
let idx = self.first_non_null().unwrap();

if T::get_dtype().is_float() {}

// SAFETY: first_non_null returns in bound index.
unsafe { self.get_unchecked(idx) }
},
IsSorted::Descending => {
self.last_non_null().and_then(|idx| {
// SAFETY: last returns in bound index.
unsafe { self.get_unchecked(idx) }
})
// if T::get_dtype().is_float() {
// let offset = self.first_non_null().unwrap();
// let length = self.last_non_null().unwrap() - offset;

// let mut arr = unsafe { self.rechunk().downcast_get_unchecked(0) };
// unsafe { arr.slice_unchecked(offset, length) };

// let idx: u64 = with_match_physical_float_type!(T::get_dtype(), |$T| {
// binary_search_array(SearchSortedSide::Left, arr, $T::NAN, false)
// });

// return None;
// }

let idx = self.last_non_null().unwrap();
unsafe { self.get_unchecked(idx) }
},
IsSorted::Not => self
.downcast_iter()
Expand Down
3 changes: 1 addition & 2 deletions crates/polars-core/src/chunked_array/ops/search_sorted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,5 @@ where
size = right - left;
}

debug_assert!(arr.len() == 0);
0 as IdxSize
left
}
13 changes: 13 additions & 0 deletions crates/polars-core/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,19 @@ macro_rules! with_match_physical_integer_type {(
}
})}

#[macro_export]
macro_rules! with_match_physical_float_type {(
$dtype:expr, | $_:tt $T:ident | $($body:tt)*
) => ({
macro_rules! __with_ty__ {( $_ $T:ident ) => ( $($body)* )}
use $crate::datatypes::DataType::*;
match $dtype {
Float32 => __with_ty__! { f32 },
Float64 => __with_ty__! { f64 },
dt => panic!("not implemented for dtype {:?}", dt),
}
})}

#[macro_export]
macro_rules! with_match_physical_float_polars_type {(
$key_type:expr, | $_:tt $T:ident | $($body:tt)*
Expand Down

0 comments on commit b0e5777

Please sign in to comment.