Skip to content

Commit

Permalink
arg_min/max to dsl
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jan 10, 2022
1 parent 2bbc851 commit 599c589
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
16 changes: 16 additions & 0 deletions polars/polars-lazy/src/dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,22 @@ impl Expr {
)
}

/// Get the index value that has the minumum value
pub fn arg_min(self) -> Self {
self.apply(
|s| Ok(Series::new(s.name(), &[s.arg_min().map(|idx| idx as u32)])),
GetOutput::from_type(DataType::UInt32),
)
}

/// Get the index value that has the maximum value
pub fn arg_max(self) -> Self {
self.apply(
|s| Ok(Series::new(s.name(), &[s.arg_max().map(|idx| idx as u32)])),
GetOutput::from_type(DataType::UInt32),
)
}

/// Get the index values that would sort this expression.
pub fn arg_sort(self, reverse: bool) -> Self {
assert!(
Expand Down
16 changes: 2 additions & 14 deletions py-polars/src/lazy/dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,22 +179,10 @@ impl PyExpr {
self.clone().inner.arg_sort(reverse).into()
}
pub fn arg_max(&self) -> PyExpr {
self.clone()
.inner
.apply(
|s| Ok(Series::new(s.name(), &[s.arg_max().map(|idx| idx as u32)])),
GetOutput::from_type(DataType::UInt32),
)
.into()
self.clone().inner.arg_max().into()
}
pub fn arg_min(&self) -> PyExpr {
self.clone()
.inner
.apply(
|s| Ok(Series::new(s.name(), &[s.arg_min().map(|idx| idx as u32)])),
GetOutput::from_type(DataType::UInt32),
)
.into()
self.clone().inner.arg_min().into()
}
pub fn take(&self, idx: PyExpr) -> PyExpr {
self.clone().inner.take(idx.inner).into()
Expand Down

0 comments on commit 599c589

Please sign in to comment.