Skip to content

Commit

Permalink
chore: move repeat_by to polars-ops (#11461)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Oct 2, 2023
1 parent 10a6852 commit 93cdd8d
Show file tree
Hide file tree
Showing 19 changed files with 142 additions and 251 deletions.
2 changes: 0 additions & 2 deletions crates/polars-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ rows = []
zip_with = []
round_series = []
checked_arithmetic = []
repeat_by = []
is_first_distinct = []
is_last_distinct = []
asof_join = []
Expand Down Expand Up @@ -147,7 +146,6 @@ docs-selection = [
"zip_with",
"round_series",
"checked_arithmetic",
"repeat_by",
"is_first_distinct",
"is_last_distinct",
"asof_join",
Expand Down
11 changes: 0 additions & 11 deletions crates/polars-core/src/chunked_array/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ mod len;
pub(crate) mod min_max_binary;
mod nulls;
mod peaks;
#[cfg(feature = "repeat_by")]
mod repeat_by;
mod reverse;
pub(crate) mod rolling_window;
mod set;
Expand Down Expand Up @@ -649,15 +647,6 @@ pub trait ChunkPeaks {
}
}

/// Repeat the values `n` times.
#[cfg(feature = "repeat_by")]
pub trait RepeatBy {
/// Repeat the values `n` times, where `n` is determined by the values in `by`.
fn repeat_by(&self, _by: &IdxCa) -> PolarsResult<ListChunked> {
unimplemented!()
}
}

#[cfg(feature = "is_first_distinct")]
/// Mask the first unique values as `true`
pub trait IsFirstDistinct<T: PolarsDataType> {
Expand Down
148 changes: 0 additions & 148 deletions crates/polars-core/src/chunked_array/ops/repeat_by.rs

This file was deleted.

5 changes: 0 additions & 5 deletions crates/polars-core/src/series/implementations/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,6 @@ impl SeriesTrait for SeriesWrap<BinaryChunked> {
Arc::new(SeriesWrap(Clone::clone(&self.0)))
}

#[cfg(feature = "repeat_by")]
fn repeat_by(&self, by: &IdxCa) -> PolarsResult<ListChunked> {
RepeatBy::repeat_by(&self.0, by)
}

#[cfg(feature = "mode")]
fn mode(&self) -> PolarsResult<Series> {
Ok(self.0.mode()?.into_series())
Expand Down
5 changes: 0 additions & 5 deletions crates/polars-core/src/series/implementations/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,6 @@ impl SeriesTrait for SeriesWrap<BooleanChunked> {
Arc::new(SeriesWrap(Clone::clone(&self.0)))
}

#[cfg(feature = "repeat_by")]
fn repeat_by(&self, by: &IdxCa) -> PolarsResult<ListChunked> {
RepeatBy::repeat_by(&self.0, by)
}

#[cfg(feature = "mode")]
fn mode(&self) -> PolarsResult<Series> {
Ok(self.0.mode()?.into_series())
Expand Down
9 changes: 0 additions & 9 deletions crates/polars-core/src/series/implementations/categorical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,6 @@ impl SeriesTrait for SeriesWrap<CategoricalChunked> {
Arc::new(SeriesWrap(Clone::clone(&self.0)))
}

#[cfg(feature = "repeat_by")]
fn repeat_by(&self, by: &IdxCa) -> PolarsResult<ListChunked> {
let out = self.0.logical().repeat_by(by)?;
let casted = out
.cast(&DataType::List(Box::new(self.dtype().clone())))
.unwrap();
Ok(casted.list().unwrap().clone())
}

#[cfg(feature = "mode")]
fn mode(&self) -> PolarsResult<Series> {
let cats = self.0.logical().mode()?;
Expand Down
22 changes: 0 additions & 22 deletions crates/polars-core/src/series/implementations/dates_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,28 +409,6 @@ macro_rules! impl_dyn_series {
fn peak_min(&self) -> BooleanChunked {
self.0.peak_min()
}
#[cfg(feature = "repeat_by")]
fn repeat_by(&self, by: &IdxCa) -> PolarsResult<ListChunked> {
match self.0.dtype() {
DataType::Date => Ok(self
.0
.repeat_by(by)?
.cast(&DataType::List(Box::new(DataType::Date)))
.unwrap()
.list()
.unwrap()
.clone()),
DataType::Time => Ok(self
.0
.repeat_by(by)?
.cast(&DataType::List(Box::new(DataType::Time)))
.unwrap()
.list()
.unwrap()
.clone()),
_ => unreachable!(),
}
}
#[cfg(feature = "mode")]
fn mode(&self) -> PolarsResult<Series> {
self.0.mode().map(|ca| ca.$into_logical().into_series())
Expand Down
14 changes: 0 additions & 14 deletions crates/polars-core/src/series/implementations/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,20 +417,6 @@ impl SeriesTrait for SeriesWrap<DatetimeChunked> {
fn peak_min(&self) -> BooleanChunked {
self.0.peak_min()
}
#[cfg(feature = "repeat_by")]
fn repeat_by(&self, by: &IdxCa) -> PolarsResult<ListChunked> {
Ok(self
.0
.repeat_by(by)?
.cast(&DataType::List(Box::new(DataType::Datetime(
self.0.time_unit(),
self.0.time_zone().clone(),
))))
.unwrap()
.list()
.unwrap()
.clone())
}
#[cfg(feature = "mode")]
fn mode(&self) -> PolarsResult<Series> {
self.0.mode().map(|ca| {
Expand Down
13 changes: 0 additions & 13 deletions crates/polars-core/src/series/implementations/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,19 +454,6 @@ impl SeriesTrait for SeriesWrap<DurationChunked> {
fn peak_min(&self) -> BooleanChunked {
self.0.peak_min()
}
#[cfg(feature = "repeat_by")]
fn repeat_by(&self, by: &IdxCa) -> PolarsResult<ListChunked> {
Ok(self
.0
.repeat_by(by)?
.cast(&DataType::List(Box::new(DataType::Duration(
self.0.time_unit(),
))))
.unwrap()
.list()
.unwrap()
.clone())
}
#[cfg(feature = "mode")]
fn mode(&self) -> PolarsResult<Series> {
self.0
Expand Down
5 changes: 0 additions & 5 deletions crates/polars-core/src/series/implementations/floats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,6 @@ macro_rules! impl_dyn_series {
self.0.peak_min()
}

#[cfg(feature = "repeat_by")]
fn repeat_by(&self, by: &IdxCa) -> PolarsResult<ListChunked> {
RepeatBy::repeat_by(&self.0, by)
}

#[cfg(feature = "checked_arithmetic")]
fn checked_div(&self, rhs: &Series) -> PolarsResult<Series> {
self.0.checked_div(rhs)
Expand Down
5 changes: 0 additions & 5 deletions crates/polars-core/src/series/implementations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,6 @@ macro_rules! impl_dyn_series {
self.0.peak_min()
}

#[cfg(feature = "repeat_by")]
fn repeat_by(&self, by: &IdxCa) -> PolarsResult<ListChunked> {
RepeatBy::repeat_by(&self.0, by)
}

#[cfg(feature = "checked_arithmetic")]
fn checked_div(&self, rhs: &Series) -> PolarsResult<Series> {
self.0.checked_div(rhs)
Expand Down
5 changes: 0 additions & 5 deletions crates/polars-core/src/series/implementations/utf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,6 @@ impl SeriesTrait for SeriesWrap<Utf8Chunked> {
Arc::new(SeriesWrap(Clone::clone(&self.0)))
}

#[cfg(feature = "repeat_by")]
fn repeat_by(&self, by: &IdxCa) -> PolarsResult<ListChunked> {
RepeatBy::repeat_by(&self.0, by)
}

#[cfg(feature = "mode")]
fn mode(&self) -> PolarsResult<Series> {
Ok(self.0.mode()?.into_series())
Expand Down
4 changes: 0 additions & 4 deletions crates/polars-core/src/series/series_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,6 @@ pub trait SeriesTrait:
invalid_operation_panic!(peak_min, self)
}

#[cfg(feature = "repeat_by")]
fn repeat_by(&self, _by: &IdxCa) -> PolarsResult<ListChunked> {
polars_bail!(opq = repeat_by, self._dtype());
}
#[cfg(feature = "checked_arithmetic")]
fn checked_div(&self, _rhs: &Series) -> PolarsResult<Series> {
polars_bail!(opq = checked_div, self._dtype());
Expand Down
1 change: 1 addition & 0 deletions crates/polars-ops/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,4 @@ list_drop_nulls = []
extract_groups = ["dtype-struct", "polars-core/regex"]
is_in = ["polars-core/reinterpret"]
convert_index = []
repeat_by = []
4 changes: 4 additions & 0 deletions crates/polars-ops/src/chunked_array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ mod sum;
mod top_k;

pub mod gather_skip_nulls;
#[cfg(feature = "repeat_by")]
mod repeat_by;

pub use binary::*;
#[cfg(feature = "timezones")]
Expand All @@ -24,6 +26,8 @@ pub use interpolate::*;
pub use list::*;
#[allow(unused_imports)]
use polars_core::prelude::*;
#[cfg(feature = "repeat_by")]
pub use repeat_by::*;
pub use set::ChunkedSet;
pub use strings::*;
#[cfg(feature = "top_k")]
Expand Down
Loading

0 comments on commit 93cdd8d

Please sign in to comment.