-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
feat: Add rolling_(min/max/sum), rolling_(min/max/sum)_by for pl.Boolean
#19112
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,7 +195,11 @@ pub trait SeriesOpsTime: AsSeries { | |
by: &Series, | ||
options: RollingOptionsDynamicWindow, | ||
) -> PolarsResult<Series> { | ||
let s = self.as_series().clone(); | ||
let mut s = self.as_series().clone(); | ||
if s.dtype().is_bool() { | ||
s = s.cast(&DataType::UInt32)?; | ||
} | ||
|
||
with_match_physical_numeric_polars_type!(s.dtype(), |$T| { | ||
let ca: &ChunkedArray<$T> = s.as_ref().as_ref().as_ref(); | ||
rolling_agg_by( | ||
|
@@ -213,6 +217,8 @@ pub trait SeriesOpsTime: AsSeries { | |
let mut s = self.as_series().clone(); | ||
if options.weights.is_some() { | ||
s = s.to_float()?; | ||
} else if s.dtype().is_bool() { | ||
s = s.cast(&DataType::UInt32)?; | ||
} | ||
|
||
with_match_physical_numeric_polars_type!(s.dtype(), |$T| { | ||
|
@@ -267,34 +273,52 @@ pub trait SeriesOpsTime: AsSeries { | |
by: &Series, | ||
options: RollingOptionsDynamicWindow, | ||
) -> PolarsResult<Series> { | ||
let s = self.as_series().clone(); | ||
let original_type = self.as_series().dtype(); | ||
let mut s = self.as_series().clone(); | ||
if s.dtype().is_bool() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really don't think we should cast here, but rather have a specialize algorithm for booleans. |
||
s = s.cast(&DataType::UInt32)?; | ||
} | ||
|
||
with_match_physical_numeric_polars_type!(s.dtype(), |$T| { | ||
let ca: &ChunkedArray<$T> = s.as_ref().as_ref().as_ref(); | ||
rolling_agg_by( | ||
let out = rolling_agg_by( | ||
ca, | ||
by, | ||
options, | ||
&super::rolling_kernels::no_nulls::rolling_min, | ||
) | ||
)?; | ||
if original_type.is_bool() { | ||
out.cast(original_type) | ||
} else { | ||
Ok(out) | ||
} | ||
}) | ||
} | ||
|
||
/// Apply a rolling min to a Series. | ||
#[cfg(feature = "rolling_window")] | ||
fn rolling_min(&self, options: RollingOptionsFixedWindow) -> PolarsResult<Series> { | ||
let original_type = self.as_series().dtype(); | ||
let mut s = self.as_series().clone(); | ||
if options.weights.is_some() { | ||
s = s.to_float()?; | ||
} else if s.dtype().is_bool() { | ||
s = s.cast(&DataType::UInt32)?; | ||
} | ||
|
||
with_match_physical_numeric_polars_type!(s.dtype(), |$T| { | ||
let ca: &ChunkedArray<$T> = s.as_ref().as_ref().as_ref(); | ||
rolling_agg( | ||
let out = rolling_agg( | ||
ca, | ||
options, | ||
&rolling::no_nulls::rolling_min, | ||
&rolling::nulls::rolling_min, | ||
) | ||
)?; | ||
if original_type.is_bool() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really don't think we should cast here, but rather have a specialize algorithm for booleans. |
||
out.cast(original_type) | ||
} else { | ||
Ok(out) | ||
} | ||
}) | ||
} | ||
|
||
|
@@ -305,34 +329,52 @@ pub trait SeriesOpsTime: AsSeries { | |
by: &Series, | ||
options: RollingOptionsDynamicWindow, | ||
) -> PolarsResult<Series> { | ||
let s = self.as_series().clone(); | ||
let original_type = self.as_series().dtype(); | ||
let mut s = self.as_series().clone(); | ||
if s.dtype().is_bool() { | ||
s = s.cast(&DataType::UInt32)?; | ||
} | ||
|
||
with_match_physical_numeric_polars_type!(s.dtype(), |$T| { | ||
let ca: &ChunkedArray<$T> = s.as_ref().as_ref().as_ref(); | ||
rolling_agg_by( | ||
let out = rolling_agg_by( | ||
ca, | ||
by, | ||
options, | ||
&super::rolling_kernels::no_nulls::rolling_max, | ||
) | ||
)?; | ||
if original_type.is_bool() { | ||
out.cast(original_type) | ||
} else { | ||
Ok(out) | ||
} | ||
}) | ||
} | ||
|
||
/// Apply a rolling max to a Series. | ||
#[cfg(feature = "rolling_window")] | ||
fn rolling_max(&self, options: RollingOptionsFixedWindow) -> PolarsResult<Series> { | ||
let original_type = self.as_series().dtype(); | ||
let mut s = self.as_series().clone(); | ||
if options.weights.is_some() { | ||
s = s.to_float()?; | ||
} else if s.dtype().is_bool() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really don't think we should cast here, but rather have a specialize algorithm for booleans. |
||
s = s.cast(&DataType::UInt32)?; | ||
} | ||
|
||
with_match_physical_numeric_polars_type!(s.dtype(), |$T| { | ||
let ca: &ChunkedArray<$T> = s.as_ref().as_ref().as_ref(); | ||
rolling_agg( | ||
let out = rolling_agg( | ||
ca, | ||
options, | ||
&rolling::no_nulls::rolling_max, | ||
&rolling::nulls::rolling_max, | ||
) | ||
)?; | ||
if original_type.is_bool() { | ||
out.cast(original_type) | ||
} else { | ||
Ok(out) | ||
} | ||
}) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should cast to
IdxType
.