-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from pola-rs/prev-greater
Add arg_prev_greater
- Loading branch information
Showing
6 changed files
with
158 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use polars::prelude::*; | ||
|
||
pub(crate) fn impl_arg_previous_greater<T>(ca: &ChunkedArray<T>) -> IdxCa | ||
where | ||
T: PolarsNumericType, | ||
{ | ||
let mut idx: Vec<Option<i32>> = Vec::with_capacity(ca.len()); | ||
let out: IdxCa = ca | ||
.into_iter() | ||
.enumerate() | ||
.map(|(i, opt_val)| { | ||
if opt_val.is_none() { | ||
idx.push(None); | ||
return None; | ||
} | ||
let i_curr = i; | ||
let mut i = Some((i as i32) - 1); // look at previous element | ||
while i >= Some(0) && ca.get(i.unwrap() as usize).is_none() { | ||
// find previous non-null value | ||
i = Some(i.unwrap() - 1) | ||
} | ||
if i < Some(0) { | ||
idx.push(None); | ||
return None; | ||
} | ||
while i.is_some() && opt_val >= ca.get(i.unwrap() as usize) { | ||
i = idx[i.unwrap() as usize]; | ||
} | ||
if i.is_none() { | ||
idx.push(None); | ||
return Some(i_curr as IdxSize); | ||
} | ||
idx.push(i); | ||
i.map(|x| x as IdxSize) | ||
}) | ||
.collect(); | ||
out | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod arg_previous_greater; | ||
mod business_days; | ||
mod expressions; | ||
mod format_localized; | ||
|