Skip to content
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

chore: Move horizontal methods to polars-ops #20134

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 0 additions & 81 deletions crates/polars-core/src/chunked_array/ops/min_max_binary.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/polars-core/src/chunked_array/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ pub mod float_sorted_arg_max;
mod for_each;
pub mod full;
pub mod gather;
#[cfg(feature = "zip_with")]
pub(crate) mod min_max_binary;
pub(crate) mod nulls;
mod reverse;
#[cfg(feature = "rolling_window")]
Expand Down
68 changes: 0 additions & 68 deletions crates/polars-core/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::chunked_array::metadata::MetadataFlags;
#[cfg(feature = "algorithm_group_by")]
use crate::chunked_array::ops::unique::is_unique_helper;
use crate::prelude::*;
use crate::series::arithmetic::horizontal as series_horizontal;
#[cfg(feature = "row_hash")]
use crate::utils::split_df;
use crate::utils::{slice_offsets, try_get_supertype, Container, NoNull};
Expand Down Expand Up @@ -43,12 +42,6 @@ use crate::prelude::sort::{argsort_multiple_row_fmt, prepare_arg_sort};
use crate::series::IsSorted;
use crate::POOL;

#[derive(Copy, Clone, Debug)]
pub enum NullStrategy {
Ignore,
Propagate,
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, Default, Hash, IntoStaticStr)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[strum(serialize_all = "snake_case")]
Expand Down Expand Up @@ -2791,28 +2784,6 @@ impl DataFrame {
Ok(unsafe { DataFrame::new_no_checks(self.height(), col) })
}

/// Aggregate the column horizontally to their min values.
#[cfg(feature = "zip_with")]
pub fn min_horizontal(&self) -> PolarsResult<Option<Column>> {
series_horizontal::min_horizontal(&self.columns)
}

/// Aggregate the column horizontally to their max values.
#[cfg(feature = "zip_with")]
pub fn max_horizontal(&self) -> PolarsResult<Option<Column>> {
series_horizontal::max_horizontal(&self.columns)
}

/// Sum all values horizontally across columns.
pub fn sum_horizontal(&self, null_strategy: NullStrategy) -> PolarsResult<Option<Column>> {
series_horizontal::sum_horizontal(&self.columns, null_strategy)
}

/// Compute the mean of all numeric values horizontally across columns.
pub fn mean_horizontal(&self, null_strategy: NullStrategy) -> PolarsResult<Option<Column>> {
series_horizontal::mean_horizontal(&self.columns, null_strategy)
}

/// Pipe different functions/ closure operations that work on a DataFrame together.
pub fn pipe<F, B>(self, f: F) -> PolarsResult<B>
where
Expand Down Expand Up @@ -3515,45 +3486,6 @@ mod test {
assert_eq!(df.height, 6)
}

#[test]
#[cfg(feature = "zip_with")]
#[cfg_attr(miri, ignore)]
fn test_horizontal_agg() {
let a = Column::new("a".into(), [1, 2, 6]);
let b = Column::new("b".into(), [Some(1), None, None]);
let c = Column::new("c".into(), [Some(4), None, Some(3)]);

let df = DataFrame::new(vec![a, b, c]).unwrap();
assert_eq!(
Vec::from(
df.mean_horizontal(NullStrategy::Ignore)
.unwrap()
.unwrap()
.f64()
.unwrap()
),
&[Some(2.0), Some(2.0), Some(4.5)]
);
assert_eq!(
Vec::from(
df.sum_horizontal(NullStrategy::Ignore)
.unwrap()
.unwrap()
.i32()
.unwrap()
),
&[Some(6), Some(2), Some(9)]
);
assert_eq!(
Vec::from(df.min_horizontal().unwrap().unwrap().i32().unwrap()),
&[Some(1), Some(2), Some(3)]
);
assert_eq!(
Vec::from(df.max_horizontal().unwrap().unwrap().i32().unwrap()),
&[Some(4), Some(2), Some(6)]
);
}

#[test]
fn test_replace_or_add() -> PolarsResult<()> {
let mut df = df!(
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-core/src/series/arithmetic/borrowed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ pub mod checked {
}
}

pub(crate) fn coerce_lhs_rhs<'a>(
pub fn coerce_lhs_rhs<'a>(
lhs: &'a Series,
rhs: &'a Series,
) -> PolarsResult<(Cow<'a, Series>, Cow<'a, Series>)> {
Expand Down
Loading
Loading