Skip to content

Commit

Permalink
improve rolling_agg (#3101)
Browse files Browse the repository at this point in the history
handle NaNs with IsFloat trait
  • Loading branch information
ritchie46 committed Apr 11, 2022
1 parent 36a83fc commit 615127a
Show file tree
Hide file tree
Showing 7 changed files with 421 additions and 233 deletions.
39 changes: 39 additions & 0 deletions polars/polars-arrow/src/data_types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
pub trait IsFloat {
fn is_float() -> bool {
false
}

#[allow(clippy::wrong_self_convention)]
fn is_nan(self) -> bool
where
Self: Sized,
{
false
}
}

impl IsFloat for i8 {}
impl IsFloat for i16 {}
impl IsFloat for i32 {}
impl IsFloat for i64 {}
impl IsFloat for u8 {}
impl IsFloat for u16 {}
impl IsFloat for u32 {}
impl IsFloat for u64 {}

macro_rules! impl_is_float {
($tp:ty) => {
impl IsFloat for $tp {
fn is_float() -> bool {
true
}

fn is_nan(self) -> bool {
<$tp>::is_nan(self)
}
}
};
}

impl_is_float!(f32);
impl_is_float!(f64);

0 comments on commit 615127a

Please sign in to comment.