Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rust, python): fix is_sorted for structs #10099

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions polars/polars-ops/src/series/ops/various.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,26 @@ pub trait SeriesMethods: SeriesSealed {
// Compare adjacent elements with no-copy slices that don't include any nulls
let offset = !options.nulls_last as i64 * nc as i64;
let (s1, s2) = (s.slice(offset, slen), s.slice(offset + 1, slen));
match options.descending {
true => Ok(Series::gt_eq(&s1, &s2)?.all()),
false => Ok(Series::lt_eq(&s1, &s2)?.all()),
let cmp_op = match options.descending {
true => Series::gt_eq,
false => Series::lt_eq,
};
match s.dtype() {
// For structs compare per-field. We don't have to check any types or field names though
// since we're just comparing two offset slices of the same Series. The loop is to both
// short-circuit on false and propagate errors. Maybe there's a way with iterators?
#[cfg(feature = "dtype-struct")]
DataType::Struct(_) => {
let mut struct_cmp = true;
for (l, r) in s1.struct_()?.fields().iter().zip(s2.struct_()?.fields()) {
struct_cmp &= cmp_op(l, r)?.all();
if !struct_cmp {
break;
}
}
Ok(struct_cmp)
}
_ => Ok(cmp_op(&s1, &s2)?.all()),
}
}
}
Expand Down