Skip to content

Commit

Permalink
refactor[rust]: remove agg_quantile from series trait (#4964)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Sep 24, 2022
1 parent d12be1c commit 6b647d4
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 66 deletions.
37 changes: 36 additions & 1 deletion polars/polars-core/src/frame/groupby/aggregations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,45 @@ impl Series {
Float64 => SeriesWrap(self.f64().unwrap().clone()).agg_median(groups),
dt if dt.is_numeric() || dt.is_temporal() => {
let ca = self.to_physical_repr();
let physical_type = ca.dtype();
let s = apply_method_physical_integer!(ca, agg_median, groups);
if dt.is_logical() {
// back to physical and then
// back to logical type
s.cast(dt).unwrap()
s.cast(physical_type).unwrap().cast(dt).unwrap()
} else {
s
}
}
_ => Series::full_null("", groups.len(), self.dtype()),
}
}

#[doc(hidden)]
pub unsafe fn agg_quantile(
&self,
groups: &GroupsProxy,
quantile: f64,
interpol: QuantileInterpolOptions,
) -> Series {
use DataType::*;

match self.dtype() {
Float32 => {
SeriesWrap(self.f32().unwrap().clone()).agg_quantile(groups, quantile, interpol)
}
Float64 => {
SeriesWrap(self.f64().unwrap().clone()).agg_quantile(groups, quantile, interpol)
}
dt if dt.is_numeric() || dt.is_temporal() => {
let ca = self.to_physical_repr();
let physical_type = ca.dtype();
let s =
apply_method_physical_integer!(ca, agg_quantile, groups, quantile, interpol);
if dt.is_logical() {
// back to physical and then
// back to logical type
s.cast(physical_type).unwrap().cast(dt).unwrap()
} else {
s
}
Expand Down
12 changes: 0 additions & 12 deletions polars/polars-core/src/series/implementations/dates_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,6 @@ macro_rules! impl_dyn_series {
.unwrap()
}

unsafe fn agg_quantile(
&self,
groups: &GroupsProxy,
quantile: f64,
interpol: QuantileInterpolOptions,
) -> Series {
self.0
.agg_quantile(groups, quantile, interpol)
.$into_logical()
.into_series()
}

fn zip_outer_join_column(
&self,
right_column: &Series,
Expand Down
12 changes: 0 additions & 12 deletions polars/polars-core/src/series/implementations/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,6 @@ impl private::PrivateSeries for SeriesWrap<DatetimeChunked> {
.unwrap()
}

unsafe fn agg_quantile(
&self,
groups: &GroupsProxy,
quantile: f64,
interpol: QuantileInterpolOptions,
) -> Series {
self.0
.agg_quantile(groups, quantile, interpol)
.into_datetime(self.0.time_unit(), self.0.time_zone().clone())
.into_series()
}

fn zip_outer_join_column(
&self,
right_column: &Series,
Expand Down
15 changes: 0 additions & 15 deletions polars/polars-core/src/series/implementations/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,6 @@ impl private::PrivateSeries for SeriesWrap<DurationChunked> {
.unwrap()
}

unsafe fn agg_quantile(
&self,
groups: &GroupsProxy,
quantile: f64,
interpol: QuantileInterpolOptions,
) -> Series {
self.0
.agg_quantile(groups, quantile, interpol)
// cast f64 back to physical type
.cast(&DataType::Int64)
.unwrap()
.into_duration(self.0.time_unit())
.into_series()
}

fn zip_outer_join_column(
&self,
right_column: &Series,
Expand Down
9 changes: 0 additions & 9 deletions polars/polars-core/src/series/implementations/floats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,6 @@ macro_rules! impl_dyn_series {
self.0.agg_list(groups)
}

unsafe fn agg_quantile(
&self,
groups: &GroupsProxy,
quantile: f64,
interpol: QuantileInterpolOptions,
) -> Series {
self.agg_quantile(groups, quantile, interpol)
}

fn zip_outer_join_column(
&self,
right_column: &Series,
Expand Down
9 changes: 0 additions & 9 deletions polars/polars-core/src/series/implementations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,6 @@ macro_rules! impl_dyn_series {
self.0.agg_list(groups)
}

unsafe fn agg_quantile(
&self,
groups: &GroupsProxy,
quantile: f64,
interpol: QuantileInterpolOptions,
) -> Series {
self.0.agg_quantile(groups, quantile, interpol)
}

fn zip_outer_join_column(
&self,
right_column: &Series,
Expand Down
8 changes: 0 additions & 8 deletions polars/polars-core/src/series/series_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,6 @@ pub(crate) mod private {
unsafe fn agg_list(&self, groups: &GroupsProxy) -> Series {
Series::full_null(self._field().name(), groups.len(), self._dtype())
}
unsafe fn agg_quantile(
&self,
groups: &GroupsProxy,
_quantile: f64,
_interpol: QuantileInterpolOptions,
) -> Series {
Series::full_null(self._field().name(), groups.len(), self._dtype())
}

fn zip_outer_join_column(
&self,
Expand Down

0 comments on commit 6b647d4

Please sign in to comment.