Skip to content

Commit

Permalink
fix(rust, python): partially assert sortedness in groupby dynamic (po…
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored and vincent committed Feb 9, 2023
1 parent 9a68d46 commit 950fde6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions polars/polars-time/src/groupby/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ impl Wrap<&DataFrame> {
let groups = if by.is_empty() {
let vals = dt.downcast_iter().next().unwrap();
let ts = vals.values().as_slice();
partially_check_sorted(ts);
let (groups, lower, upper) = groupby_windows(
w,
ts,
Expand Down
4 changes: 2 additions & 2 deletions polars/polars-time/src/windows/groupby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,13 +360,13 @@ pub(crate) fn groupby_values_iter_full_lookahead(
})
}

fn partially_check_sorted(time: &[i64]) {
pub(crate) fn partially_check_sorted(time: &[i64]) {
// check sortedness of a small subslice.
if time.len() > 1 {
assert!(time[..std::cmp::min(time.len(), 10)].windows(2).filter_map(|w| match w[0].cmp(&w[1]) {
Ordering::Equal => None,
t => Some(t)
}).all_equal(), "Subslice check showed that the values in `groupby_rolling` were not sorted. Pleasure ensure the index column is sorted.");
}).all_equal(), "Subslice check showed that the values in `groupby_rolling/groupby_dynamic` were not sorted. Pleasure ensure the index column is sorted.");
}
}

Expand Down
3 changes: 3 additions & 0 deletions py-polars/polars/internals/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3677,6 +3677,9 @@ def groupby_dynamic(
- "1i" # length 1
- "10i" # length 10
.. warning::
The index column must be sorted in ascending order.
Parameters
----------
index_column
Expand Down
3 changes: 3 additions & 0 deletions py-polars/polars/internals/lazyframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,9 @@ def groupby_dynamic(
- "1i" # length 1
- "10i" # length 10
.. warning::
The index column must be sorted in ascending order.
Parameters
----------
index_column
Expand Down

0 comments on commit 950fde6

Please sign in to comment.