diff --git a/polars/polars-time/src/groupby/dynamic.rs b/polars/polars-time/src/groupby/dynamic.rs index b464b75d00509..ad4eb11a2230e 100644 --- a/polars/polars-time/src/groupby/dynamic.rs +++ b/polars/polars-time/src/groupby/dynamic.rs @@ -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, diff --git a/polars/polars-time/src/windows/groupby.rs b/polars/polars-time/src/windows/groupby.rs index c2fef164cb9cd..387996a47e20d 100644 --- a/polars/polars-time/src/windows/groupby.rs +++ b/polars/polars-time/src/windows/groupby.rs @@ -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."); } } diff --git a/py-polars/polars/internals/dataframe/frame.py b/py-polars/polars/internals/dataframe/frame.py index ac3ae8c5fc44c..da4e31348abd1 100644 --- a/py-polars/polars/internals/dataframe/frame.py +++ b/py-polars/polars/internals/dataframe/frame.py @@ -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 diff --git a/py-polars/polars/internals/lazyframe/frame.py b/py-polars/polars/internals/lazyframe/frame.py index d0e5de25db273..b113114108008 100644 --- a/py-polars/polars/internals/lazyframe/frame.py +++ b/py-polars/polars/internals/lazyframe/frame.py @@ -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