Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
orlp committed Sep 3, 2024
1 parent 8748678 commit ee3b8df
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 44 deletions.
78 changes: 44 additions & 34 deletions crates/polars-core/src/datatypes/any_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -947,12 +947,12 @@ impl AnyValue<'_> {
(l, StringOwned(r)) => *l == AnyValue::String(r.as_str()),
(l, BinaryOwned(r)) => *l == AnyValue::Binary(r.as_slice()),
(l, ObjectOwned(r)) => *l == AnyValue::Object(&*r.0),

// Comparison with null.
(Null, Null) => null_equal,
(Null, _) => false,
(_, Null) => false,

// Equality between equal types.
(Boolean(l), Boolean(r)) => *l == *r,
(UInt8(l), UInt8(r)) => *l == *r,
Expand All @@ -979,17 +979,19 @@ impl AnyValue<'_> {
#[cfg(feature = "dtype-categorical")]
(Categorical(idx_l, rev_l, ptr_l), Categorical(idx_r, rev_r, ptr_r)) => {
if !same_revmap(rev_l, *ptr_l, rev_r, *ptr_r) {
unimplemented!("comparing categoricals with different revmaps is not supported");
unimplemented!(
"comparing categoricals with different revmaps is not supported"
);
}

idx_l == idx_r
},
#[cfg(feature = "dtype-categorical")]
(Enum(idx_l, rev_l, ptr_l), Enum(idx_r, rev_r, ptr_r)) => {
if !same_revmap(rev_l, *ptr_l, rev_r, *ptr_r) {
unimplemented!("comparing enums with different revmaps is not supported");
}

idx_l == idx_r
},
#[cfg(feature = "dtype-duration")]
Expand All @@ -1002,7 +1004,8 @@ impl AnyValue<'_> {
},
#[cfg(feature = "dtype-struct")]
(StructOwned(l), Struct(idx, arr, fields)) => {
l.0.iter().eq_by_(struct_av_iter(*idx, arr, fields), |lv, rv| *lv == rv)
l.0.iter()
.eq_by_(struct_av_iter(*idx, arr, fields), |lv, rv| *lv == rv)
},
#[cfg(feature = "dtype-struct")]
(Struct(idx, arr, fields), StructOwned(r)) => {
Expand Down Expand Up @@ -1041,10 +1044,10 @@ impl AnyValue<'_> {
},
#[cfg(feature = "object")]
(Object(l), Object(r)) => l == r,

(_, _) => {
unimplemented!("ordering for mixed dtypes is not supported")
}
},
}
}
}
Expand Down Expand Up @@ -1073,7 +1076,7 @@ impl PartialOrd for AnyValue<'_> {
(Null, Null) => Some(Ordering::Equal),
(Null, _) => Some(Ordering::Less),
(_, Null) => Some(Ordering::Greater),

// Comparison between equal types.
(Boolean(l), Boolean(r)) => l.partial_cmp(r),
(UInt8(l), UInt8(r)) => l.partial_cmp(r),
Expand All @@ -1093,42 +1096,49 @@ impl PartialOrd for AnyValue<'_> {
#[cfg(feature = "dtype-datetime")]
(Datetime(lt, lu, lz), Datetime(rt, ru, rz)) => {
if lu != ru || lz != rz {
unimplemented!("comparing datetimes with different units or timezones is not supported");
unimplemented!(
"comparing datetimes with different units or timezones is not supported"
);
}

lt.partial_cmp(rt)
}
},
#[cfg(feature = "dtype-duration")]
(Duration(lt, lu), Duration(rt, ru)) => {
if lu != ru {
unimplemented!("comparing durations with different units is not supported");
}

lt.partial_cmp(rt)
}
},
#[cfg(feature = "dtype-time")]
(Time(l), Time(r)) => l.partial_cmp(r),
#[cfg(feature = "dtype-categorical")]
(Categorical(..), Categorical(..)) => {
unimplemented!("can't order categoricals as AnyValues, dtype for ordering is needed")
}
unimplemented!(
"can't order categoricals as AnyValues, dtype for ordering is needed"
)
},
#[cfg(feature = "dtype-categorical")]
(Enum(..), Enum(..)) => {
unimplemented!("can't order enums as AnyValues, dtype for ordering is needed")
}
},
(List(_), List(_)) => {
unimplemented!("ordering for List dtype is not supported")
}
},
#[cfg(feature = "dtype-array")]
(Array(..), Array(..)) => {
unimplemented!("ordering for Array dtype is not supported")
}
},
#[cfg(feature = "object")]
(Object(_), Object(_)) => {
unimplemented!("ordering for Object dtype is not supported")
}
},
#[cfg(feature = "dtype-struct")]
(StructOwned(_), StructOwned(_)) | (StructOwned(_), Struct(..)) | (Struct(..), StructOwned(_)) | (Struct(..), Struct(..)) => {
(StructOwned(_), StructOwned(_))
| (StructOwned(_), Struct(..))
| (Struct(..), StructOwned(_))
| (Struct(..), Struct(..)) => {
unimplemented!("ordering for Struct dtype is not supported")
},
#[cfg(feature = "dtype-decimal")]
Expand Down Expand Up @@ -1157,11 +1167,11 @@ impl PartialOrd for AnyValue<'_> {
Some(Ordering::Less)
}
}
}
},

(_, _) => {
unimplemented!("ordering for mixed dtypes is not supported")
}
},
}
}
}
Expand Down Expand Up @@ -1191,28 +1201,28 @@ fn struct_to_avs_static(idx: usize, arr: &StructArray, fields: &[Field]) -> Vec<

#[cfg(feature = "dtype-categorical")]
fn same_revmap(
rev_l: &RevMapping,
rev_l: &RevMapping,
ptr_l: SyncPtr<Utf8ViewArray>,
rev_r: &RevMapping,
rev_r: &RevMapping,
ptr_r: SyncPtr<Utf8ViewArray>,
) -> bool {
if ptr_l.is_null() && ptr_r.is_null() {
match (rev_l, rev_r) {
(RevMapping::Global(_, _, id_l), RevMapping::Global(_, _, id_r)) => {
id_l == id_r
},
(RevMapping::Local(_, id_l), RevMapping::Local(_, id_r)) => {
id_l == id_r
},
_ => false
(RevMapping::Global(_, _, id_l), RevMapping::Global(_, _, id_r)) => id_l == id_r,
(RevMapping::Local(_, id_l), RevMapping::Local(_, id_r)) => id_l == id_r,
_ => false,
}
} else {
ptr_l == ptr_r
}
}

#[cfg(feature = "dtype-struct")]
fn struct_av_iter<'a>(idx: usize, arr: &'a StructArray, fields: &'a [Field]) -> impl Iterator<Item = AnyValue<'a>> {
fn struct_av_iter<'a>(
idx: usize,
arr: &'a StructArray,
fields: &'a [Field],
) -> impl Iterator<Item = AnyValue<'a>> {
let arrs = arr.values();
(0..arrs.len()).map(move |i| unsafe {
let arr = &**arrs.get_unchecked_release(i);
Expand Down
16 changes: 6 additions & 10 deletions crates/polars-utils/src/itertools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub trait Itertools: Iterator {
Some(a) => self.all(|x| a == x),
}
}

// Stable copy of the unstable eq_by from the stdlib.
fn eq_by_<I, F>(mut self, other: I, mut eq: F) -> bool
where
Expand All @@ -76,7 +76,7 @@ pub trait Itertools: Iterator {
} else {
return false;
}
}
},
}
}
}
Expand All @@ -94,17 +94,13 @@ pub trait Itertools: Iterator {
(None, None) => return Some(Ordering::Equal),
(None, Some(_)) => return Some(Ordering::Less),
(Some(_), None) => return Some(Ordering::Greater),
(Some(l), Some(r)) => {
match partial_cmp(l, r) {
Some(Ordering::Equal) => continue,
ord => return ord,
}
}
(Some(l), Some(r)) => match partial_cmp(l, r) {
Some(Ordering::Equal) => continue,
ord => return ord,
},
}
}
}
}


impl<T: Iterator + ?Sized> Itertools for T {}

0 comments on commit ee3b8df

Please sign in to comment.